public class FastFindCache
extends java.lang.Object
The first two levels of cache size are not limited. They are the table and indexes unique ids and are
stable, governed by database structure. Only the very last level is an actual LRUCache
object
whose size will need to be configured based on how many records should be cached for each index of a
table. However, since the invalidation of the cache will occur quite often, the value can be kept small.
Cache Invalidation: the cache is individually invalidated for each affected index when a record is updated. On insert and delete operations all indices are invalidated for respective table. On a rollback event all affected tables are invalidated.
Concurrency: The cache access is thread-safe for temporary because the instances are context local. When
accessing the permanent table shared instance, all accesses are synchronized since the LRU cache
implementation also alter the internal structure.
TODO: implement support for Resolvable
substitution parameters.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
FastFindCache.Key
A special key used for accessing values in cache.
|
private static class |
FastFindCache.L2Key
The second level key for Fast Find algorithm.
|
private static class |
FastFindCache.ReverseLookup
A reverse cache of record identifiers to values which contain information to enable the quick
invalidation of individual, cached results from the primary cache.
|
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.Long,java.util.Map<java.lang.Integer,Cache<FastFindCache.L2Key,RecordIdentifier<java.lang.String>>>> |
cache
The internal data, as a triple-level cache: table-uid x index x other-information.
|
static RecordIdentifier<java.lang.String> |
NO_RECORD
Constant for representing a negative result (i.e., the lack of result) for a query.
|
private static FastFindCache |
permanentInstance
The singleton instance for permanent database(s).
|
private FastFindCache.ReverseLookup |
reverseLookup
Reverse cache of record identifiers to invalidation info, for queries with non-indexed properties
|
private static ContextLocal<FastFindCache> |
tempTableInstances
The context-local instance for the current session for temp-tables.
|
Constructor and Description |
---|
FastFindCache() |
Modifier and Type | Method and Description |
---|---|
static long |
combine(int uid,
java.lang.Integer multiplex)
Combines the DMO uid and the optional temp-table multiplex value into a single
long value. |
(package private) static FastFindCache.Key |
createKey(RecordBuffer buffer,
int indexId,
java.lang.String fql,
java.util.BitSet properties,
int type,
java.lang.Object[] values)
Creates a cache key.
|
RecordIdentifier<java.lang.String> |
get(FastFindCache.Key k)
Query the cache for a value.
|
static FastFindCache |
getInstance(boolean temporary)
Obtain the singleton instance, if FastFind mode enabled.
|
void |
invalidate(java.util.Collection<java.lang.Long> dmoList)
Invalidates records from a list of DMOs.
|
void |
invalidate(int dmoUid,
java.lang.Integer multiplex)
Invalidates all indexes of a table.
|
void |
invalidate(int dmoUid,
java.lang.Integer multiplex,
java.util.BitSet unique,
java.util.BitSet nonUnique)
Invalidates the index for a table.
|
void |
invalidate(int dmoUid,
java.lang.Integer multiplex,
int idxUid)
Invalidate a single index of a table.
|
void |
invalidate(java.lang.String dmoName,
long id,
java.util.BitSet dirtyProps)
Invalidate any cached result which matches the given DMO name and primary key, iff
dirtyProps
intersects with the set of non-indexed properties used in the associated FQL query. |
void |
put(FastFindCache.Key k,
Record value)
Saves a result in cache.
|
private void |
synchronize(java.lang.Runnable code)
Run a piece of code optionally synchronized.
|
public static final RecordIdentifier<java.lang.String> NO_RECORD
private static final FastFindCache permanentInstance
private static final ContextLocal<FastFindCache> tempTableInstances
private final java.util.Map<java.lang.Long,java.util.Map<java.lang.Integer,Cache<FastFindCache.L2Key,RecordIdentifier<java.lang.String>>>> cache
private final FastFindCache.ReverseLookup reverseLookup
public static FastFindCache getInstance(boolean temporary)
null
to disable FastFind mode.temporary
- Use true
to get the instance object for a temp-table database. They are context-local
objects. When false
the global instance for permanent databases is returned.FastFindCache
, or null
if FastFind mode is disabled.public static long combine(int uid, java.lang.Integer multiplex)
long
value.uid
- The DMO uid.multiplex
- The multiplex
value of a temp-table. Must be positive. Use 0 or null
for
permanent tables.long
value used as level 1 key in cache.static FastFindCache.Key createKey(RecordBuffer buffer, int indexId, java.lang.String fql, java.util.BitSet properties, int type, java.lang.Object[] values)
If provided, all substitution parameters (values
) are checked if they are instances of
Resolvable
. These are not yet supported so no key is generated if they are encountered.
buffer
- The buffer that holds the record. Used for obtaining the DMO uid and multiplex (for
temp-tables).indexId
- The id of the index used when executing the query.fql
- The fql of the query which selected the keyed record.properties
- The set of properties used in fql
.type
- The type of navigation. Must be one of FIRST
, LAST
or UNIQUE
values
of the QueryConstants
.values
- The substitution values. May be null
.Key
for the provided parameters or null
if not supported.public RecordIdentifier<java.lang.String> get(FastFindCache.Key k)
k
- The key for cache.RecordIdentifier
structure. In the case of a cache-hit, this is the key for
a Session
cache, and null
otherwise.public void put(FastFindCache.Key k, Record value)
null
.k
- The key for cache.value
- The value to be stored in cache. Only the primary key is important. If null
, -1 will
be used to mark the result as not present in database.public void invalidate(int dmoUid, java.lang.Integer multiplex, java.util.BitSet unique, java.util.BitSet nonUnique)
dmoUid
- The unique id of the table.unique
- The set of dirty unique indices which need to be invalidated.nonUnique
- The set of dirty unique indices which need to be invalidated.public void invalidate(java.lang.String dmoName, long id, java.util.BitSet dirtyProps)
dirtyProps
intersects with the set of non-indexed properties used in the associated FQL query.dmoName
- DMO implementation class name of the record that was touched.id
- Primary key of the DMO that was touched.dirtyProps
- The set of properties touched by an update to the DMO.public void invalidate(int dmoUid, java.lang.Integer multiplex)
dmoUid
- The table uid whose indexes are invalidated.public void invalidate(int dmoUid, java.lang.Integer multiplex, int idxUid)
dmoUid
- The table uid whose indexes are invalidated.multiplex
- Multiplex ID for a temp-table (null
for a persistent table).idxUid
- Index identifier, unique to its table.public void invalidate(java.util.Collection<java.lang.Long> dmoList)
dmoList
- The collection of unique identifiers of the DMOs to be invalidated.private void synchronize(java.lang.Runnable code)
code
- The code to be executed.