org.mapdb
Class Caches.HardRef
java.lang.Object
org.mapdb.EngineWrapper
org.mapdb.Caches.LRU
org.mapdb.Caches.HardRef
- All Implemented Interfaces:
- Engine
- Enclosing class:
- Caches
public static class Caches.HardRef
- extends Caches.LRU
Cache created objects using hard reference.
It checks free memory every N operations (1024*10). If free memory is bellow 75% it clears the cache
- Author:
- Jan Kotek
|
Method Summary |
|
compareAndSwap(long recid,
A expectedOldValue,
A newValue,
Serializer<A> serializer)
Updates existing record in atomic (Compare And Swap) manner. |
|
delete(long recid,
Serializer<A> serializer)
Remove existing record from store/cache
Recid must be a number returned by 'put' method. |
|
get(long recid,
Serializer<A> serializer)
Get existing record. |
|
update(long recid,
A value,
Serializer<A> serializer)
Update existing record with new value. |
| Methods inherited from class org.mapdb.EngineWrapper |
canRollback, canSnapshot, checkClosed, closeListenerRegister, closeListenerUnregister, commit, compact, getSerializerPojo, getWrappedEngine, isClosed, isReadOnly, preallocate, preallocate, snapshot |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Caches.HardRef
public Caches.HardRef(Engine engine,
int initialCapacity,
boolean disableLocks)
get
public <A> A get(long recid,
Serializer<A> serializer)
- Description copied from interface:
Engine
- Get existing record.
Recid must be a number returned by 'put' method.
Behaviour for invalid recid (random number or already deleted record)
is not defined, typically it returns null or throws 'EndOfFileException'
- Specified by:
get in interface Engine- Overrides:
get in class Caches.LRU
- Parameters:
recid - (record identifier) under which record was persistedserializer - used to deserialize record from binary form
- Returns:
- record matching given recid, or null if record is not found under given recid.
update
public <A> void update(long recid,
A value,
Serializer<A> serializer)
- Description copied from interface:
Engine
- Update existing record with new value.
Recid must be a number returned by 'put' method.
Behaviour for invalid recid (random number or already deleted record)
is not defined, typically it throws 'EndOfFileException',
but it may also corrupt store.
- Specified by:
update in interface Engine- Overrides:
update in class Caches.LRU
- Parameters:
recid - (record identifier) under which record was persisted.value - new record value to be storedserializer - used to serialize record into binary form
delete
public <A> void delete(long recid,
Serializer<A> serializer)
- Description copied from interface:
Engine
- Remove existing record from store/cache
Recid must be a number returned by 'put' method.
Behaviour for invalid recid (random number or already deleted record)
is not defined, typically it throws 'EndOfFileException',
but it may also corrupt store.
- Specified by:
delete in interface Engine- Overrides:
delete in class Caches.LRU
- Parameters:
recid - (record identifier) under which was record persistedserializer - which may be used in some circumstances to deserialize and store old object
compareAndSwap
public <A> boolean compareAndSwap(long recid,
A expectedOldValue,
A newValue,
Serializer<A> serializer)
- Description copied from interface:
Engine
- Updates existing record in atomic (Compare And Swap) manner.
Value is modified only if old value matches expected value. There are three ways to match values, MapDB may use any of them:
- Equality check
oldValue==expectedOldValue when old value is found in instance cache
- Deserializing
oldValue using serializer and checking oldValue.equals(expectedOldValue)
- Serializing
expectedOldValue using serializer and comparing binary array with already serialized oldValue
Recid must be a number returned by 'put' method.
Behaviour for invalid recid (random number or already deleted record)
is not defined, typically it throws 'EndOfFileException',
but it may also corrupt store.
- Specified by:
compareAndSwap in interface Engine- Overrides:
compareAndSwap in class Caches.LRU
- Parameters:
recid - (record identifier) under which record was persisted.expectedOldValue - old value to be compared with existing recordnewValue - to be written if values are matchingserializer - used to serialize record into binary form
- Returns:
- true if values matched and newValue was written
Copyright © 2014. All Rights Reserved.