Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.openjpa.datacache
Class ConcurrentQueryCache

    java.lang.Object
      org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
          org.apache.openjpa.datacache.AbstractQueryCache
              org.apache.openjpa.datacache.ConcurrentQueryCache

All Implemented Interfaces:
  QueryCache, TypesChangedListener, RemoteCommitListener, Configurable, Closeable, EventManager

    public class ConcurrentQueryCache

extends AbstractQueryCache
implements RemoteCommitListener

A `QueryCache` implementation that is optimized for concurrent access. When the cache fill up, values to remove from the cache are chosen randomly. Due to race conditions, it is possible that a get call might not retur a cached instance if that instance is being transferred between internal datastructures.

Since:
  0.4.1

Field Summary

Fields inherited from class org.apache.openjpa.datacache.AbstractQueryCache
`conf, log`

Constructor Summary
`ConcurrentQueryCache()`

Method Summary
`protected void` | `clearInternal()` Clear the cache.
`CacheMap` | `getCacheMap()` Returns the underlying `CacheMap` that this cache is using.
`int` | `getCacheSize()` Returns the maximum number of unpinned objects to keep hard references to.
`protected QueryResult` | `getInternal(QueryKey qk)` Return the list for the given key.
`int` | `getSoftReferenceSize()` Returns the maximum number of unpinned objects to keep soft references to.
`void` | `initialize(DataCacheManager mgr)` Initialize any resources associated with the given `DataCacheManager`.
`protected Collection` | `keySet()` Return a threadsafe view of the keys in this cache.
`protected CacheMap` | `newCacheMap()` Return the map to use as an internal cache.
`protected boolean` | `pinInternal(QueryKey qk)` Pin an object to the cache.
`protected QueryResult` | `putInternal(QueryKey qk, QueryResult result)` Add the given result to the cache, returning the old result under the given key.
`protected QueryResult` | `removeInternal(QueryKey qk)` Remove the result under the given key from the cache.
`void` | `setCacheSize(int size)` Sets the maximum number of unpinned objects to keep hard references to.
`void` | `setSoftReferenceSize(int size)` Sets the maximum number of unpinned objects to keep soft references to.
`protected boolean` | `unpinInternal(QueryKey qk)` Unpin an object from the cache.
`void` | `writeLock()` Obtain a write lock on the cache.
`void` | `writeUnlock()` Release the write lock on the cache.

Methods inherited from class org.apache.openjpa.datacache.AbstractQueryCache
`addTypesChangedListener, afterCommit, clear, close, close, endConfiguration, fireEvent, get, isClosed, newListenerCollection, onTypesChanged, pin, put, remove, removeAllInternal, removeTypesChangedListener, setConfiguration, startConfiguration, unpin`

Methods inherited from class org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
`addListener, fireEvent, getListeners, hasListener, hasListeners, isFailFast, removeListener, setFailFast`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface org.apache.openjpa.event.RemoteCommitListener
`afterCommit, close`

Constructor Detail

### ConcurrentQueryCache

    public ConcurrentQueryCache()

Method Detail

### getCacheMap

    public CacheMap getCacheMap()

  Returns the underlying `CacheMap` that this cache is using. This is not an unmodifiable view on the map, so care should be taken with this reference. Implementations should probably not modify the contents of the cache, but should only use this reference to obtain cache metrics. Additionally, this map may contain expired data. Removal of timed-out data is done in a lazy fashion, so the actual size of the map may be greater than the number of non-expired query results in cache.

### getCacheSize

    public int getCacheSize()

  Returns the maximum number of unpinned objects to keep hard references to.

### setCacheSize

    public void setCacheSize(int size)

  Sets the maximum number of unpinned objects to keep hard references to. If the map contains more unpinned objects than `size`, then this method will result in the cache flushing old values.

### getSoftReferenceSize

    public int getSoftReferenceSize()

  Returns the maximum number of unpinned objects to keep soft references to. Defaults to `-1`.

### setSoftReferenceSize

    public void setSoftReferenceSize(int size)

  Sets the maximum number of unpinned objects to keep soft references to. If the map contains more soft references than `size`, then this method will result in the cache flushing values.

### initialize

    public void initialize(DataCacheManager mgr)

  Description copied from interface: `QueryCache`
  Initialize any resources associated with the given `DataCacheManager`.

  Specified by:
    `initialize` in interface `QueryCache`
  Overrides:
    `initialize` in class `AbstractQueryCache`

### writeLock

    public void writeLock()

  Description copied from interface: `QueryCache`
  Obtain a write lock on the cache.

  Specified by:
    `writeLock` in interface `QueryCache`

### writeUnlock

    public void writeUnlock()

  Description copied from interface: `QueryCache`
  Release the write lock on the cache.

  Specified by:
    `writeUnlock` in interface `QueryCache`

### newCacheMap

    protected CacheMap newCacheMap()

  Return the map to use as an internal cache.

### getInternal

    protected QueryResult getInternal(QueryKey qk)

  Description copied from class: `AbstractQueryCache`
  Return the list for the given key.

  Specified by:
    `getInternal` in class `AbstractQueryCache`

### putInternal

    protected QueryResult putInternal(QueryKey qk,
                                      QueryResult result)

  Description copied from class: `AbstractQueryCache`
  Add the given result to the cache, returning the old result under the given key.

  Specified by:
    `putInternal` in class `AbstractQueryCache`

### removeInternal

    protected QueryResult removeInternal(QueryKey qk)

  Description copied from class: `AbstractQueryCache`
  Remove the result under the given key from the cache.

  Specified by:
    `removeInternal` in class `AbstractQueryCache`

### clearInternal

    protected void clearInternal()

  Description copied from class: `AbstractQueryCache`
  Clear the cache.

  Specified by:
    `clearInternal` in class `AbstractQueryCache`

### pinInternal

    protected boolean pinInternal(QueryKey qk)

  Description copied from class: `AbstractQueryCache`
  Pin an object to the cache.

  Specified by:
    `pinInternal` in class `AbstractQueryCache`

### unpinInternal

    protected boolean unpinInternal(QueryKey qk)

  Description copied from class: `AbstractQueryCache`
  Unpin an object from the cache.

  Specified by:
    `unpinInternal` in class `AbstractQueryCache`

### keySet

    protected Collection keySet()

  Description copied from class: `AbstractQueryCache`
  Return a threadsafe view of the keys in this cache. This collection must be iterable without risk of concurrent modification exceptions. It does not have to implement contains() efficiently or use set semantics.

  Specified by:
    `keySet` in class `AbstractQueryCache`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2006 Apache Software Foundation. All Rights Reserved.