org.modeshape.jcr.cache.document

## Class TransactionalWorkspaceCache

- java.lang.Object
- - org.modeshape.jcr.cache.document.WorkspaceCache
  - - org.modeshape.jcr.cache.document.TransactionalWorkspaceCache

- All Implemented Interfaces:
    CachedNodeSupplier, DocumentCache, NodeCache

      public class TransactionalWorkspaceCache
      extends WorkspaceCache

  A special WorkspaceCache implementation that should be used by sessions running within user transactions.

  Normally, each `RepositoryCache` instance has for each workspace a single WorkspaceCache instance shared by all sessions. However, in the event that a session is running within a user transaction, it is possible for the session (or other sessions that are also participating in the same user transaction) to persist node changes in the document store but to not commit the transaction. This means that no other transactions should see these persisted-but-not-committed node representations. Thus, these sessions running within a user transaction cannot share the common WorkspaceCache instance, lest any node representations persisted-but-not-committed be loaded into the WorkspaceCache (leaking transaction-scoped data outside of the transaction) or the shared WorkspaceCache instance has already-cached pre-modified representations of the persisted-but-not-committed nodes (transaction-scoped changes are not visible to the transaction).

  Therefore, such sessions running within user transactions need a transactionally-scoped WorkspaceCache instance. Because the ModeShape infrastructure is not set up to handle lots of WorkspaceCache instances, we only want one instance that is actually caching nodes. Therefore, the WorkspaceCache returned from this method will never cache any nodes and will always re-read the nodes from the document store.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.modeshape.jcr.cache.document.WorkspaceCache

      `WorkspaceCache.NonSystemChangeNotifier, WorkspaceCache.SystemChangeNotifier`

  - ### Field Summary

    - ### Fields inherited from class org.modeshape.jcr.cache.document.WorkspaceCache

      `LOGGER`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `TransactionalWorkspaceCache(WorkspaceCache sharedWorkspaceCache, TransactionalWorkspaceCaches cacheManager, Transaction txn)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `changed(ChangeSet changes)` Signal that changes have been made to the persisted data.
    `void` | `changedWithinTransaction(ChangeSet changes)` Signal that this transaction-specific workspace cache needs to reflect recent changes that have been persisted but not yet committed.
    `void` | `clear()` Clears all changes in the cache.
    `protected void` | `evictChangedNodes(ChangeSet changeSet)`

    - ### Methods inherited from class org.modeshape.jcr.cache.document.WorkspaceCache

      `checkNotClosed, getAllNodeKeys, getAllNodeKeysAtAndBelow, getChildReference, getNode, getNode, getProcessKey, getRepositoryKey, getRootKey, getWorkspaceKey, getWorkspaceName, isEmpty, persistedCache, setMinimumStringLengthForBinaryStorage, signalClosed, signalClosing, signalDeleted, toString, unwrap, workspaceCache`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### TransactionalWorkspaceCache

          protected TransactionalWorkspaceCache(WorkspaceCache sharedWorkspaceCache,
                                     TransactionalWorkspaceCaches cacheManager,
                                     Transaction txn)

  - ### Method Detail

    - #### changed

          public void changed(ChangeSet changes)

      Description copied from class: `WorkspaceCache`
      Signal that changes have been made to the persisted data. Related information in the cache is cleared, and this workspace's listener is notified of the changes.
      Overrides:
        `changed` in class `WorkspaceCache`
      Parameters:
        `changes` - the changes to be made; may not be null

    - #### changedWithinTransaction

          public void changedWithinTransaction(ChangeSet changes)

      Signal that this transaction-specific workspace cache needs to reflect recent changes that have been persisted but not yet committed. Generally, the transactional workspace cache will clear any cached nodes that were included in the change set
      Parameters:
        `changes` - the changes that were persisted but not yet committed
      See Also:
        `SynchronizedTransactions.updateCache(WorkspaceCache, ChangeSet, org.modeshape.jcr.txn.Transactions.Transaction)`

    - #### clear

          public void clear()

      Description copied from interface: `NodeCache`
      Clears all changes in the cache.
      Specified by:
        `clear` in interface `NodeCache`
      Overrides:
        `clear` in class `WorkspaceCache`

    - #### evictChangedNodes

          protected void evictChangedNodes(ChangeSet changeSet)

      Overrides:
        `evictChangedNodes` in class `WorkspaceCache`

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.