public class ImageFileStorage extends Object implements CacheStorage, FlushableStorage, EntryExpiryUpdateableStorage
The storage tries to be robust and does not require a clean shutdown, so it will survive machine crashes. In this case it uses the latest data possible that is known to be intact. The amount of data loss can be controlled by specifying a commit interval.
Possible optimizations: More specialized data structures, compaction.| Modifier and Type | Class and Description |
|---|---|
static class |
ImageFileStorage.Provider |
static class |
ImageFileStorage.SlotBucket |
static class |
ImageFileStorage.Tunable
Some parameters factored out, which may be modified if needed.
|
FlushableStorage.FlushContextCacheStorage.EntryFilter, CacheStorage.EntryVisitor, CacheStorage.MultiThreadedContext, CacheStorage.VisitContext| Modifier and Type | Field and Description |
|---|---|
FreeSpaceMap |
freeMap |
| Constructor and Description |
|---|
ImageFileStorage() |
ImageFileStorage(ImageFileStorage.Tunable t) |
| Modifier and Type | Method and Description |
|---|---|
static int |
calculateCompressedLongSize(long v) |
void |
clear()
Remove the files.
|
void |
close()
Free all resources and stop operations immediately.
|
boolean |
contains(Object key)
Returns true if there is a mapping for the key.
|
void |
fastClose()
Close immediately without doing a commit.
|
void |
flush(FlushableStorage.FlushContext ctx,
long now)
Write key to object index to disk for all modified entries.
|
StorageEntry |
get(Object key)
Retrieve the entry from the storage.
|
int |
getEntryCount() |
long |
getFreeSpace() |
long |
getPutCnt() |
long |
getTotalValueSpace() |
int |
getUncommittedEntryCount() |
boolean |
isClosed() |
boolean |
isDataLost()
Flag if there was a problem at the last startup and probably some data was lost.
|
void |
open(CacheStorageContext ctx,
StorageConfiguration cfg) |
void |
put(StorageEntry e)
Store a new entry.
|
static long |
readCompressedLong(ByteBuffer b) |
boolean |
remove(Object key) |
String |
toString()
Prints out current state.
|
void |
updateEntryExpireTime(Object key,
long _millis)
Update the expiry time of a stored entry.
|
void |
visit(CacheStorage.VisitContext ctx,
CacheStorage.EntryFilter f,
CacheStorage.EntryVisitor v)
Iterate over all stored entries and call the entry visitor.
|
static void |
writeCompressedLong(ByteBuffer b,
long v)
Write a long as multiple short values.
|
public final FreeSpaceMap freeMap
public ImageFileStorage(ImageFileStorage.Tunable t) throws IOException, ClassNotFoundException
IOExceptionClassNotFoundExceptionpublic ImageFileStorage()
public void open(CacheStorageContext ctx, StorageConfiguration cfg) throws IOException
IOExceptionpublic void close() throws Exception
CacheStorageclose in interface CacheStorageExceptionpublic void clear() throws IOException
clear in interface CacheStorageIOExceptionpublic void fastClose() throws IOException
IOExceptionpublic StorageEntry get(Object key) throws IOException, ClassNotFoundException
CacheStorageDepending on the cache configuration, an exception on get is not severe. The cache will try other sources or return null.
get in interface CacheStorageIOExceptionClassNotFoundExceptionpublic boolean contains(Object key) throws IOException
CacheStorageAn exception on contains is not severe. The cache will try other sources or return null.
contains in interface CacheStorageIOExceptionpublic boolean remove(Object key) throws IOException, ClassNotFoundException
remove in interface CacheStorageIOExceptionClassNotFoundExceptionpublic void put(StorageEntry e) throws IOException, ClassNotFoundException
put in interface CacheStorageIOException - may be thrown if hope is lostClassNotFoundExceptionpublic int getEntryCount()
getEntryCount in interface CacheStoragepublic long getFreeSpace()
public long getTotalValueSpace()
public int getUncommittedEntryCount()
public boolean isDataLost()
public void flush(FlushableStorage.FlushContext ctx, long now) throws IOException
flush in interface FlushableStorageIOExceptionpublic boolean isClosed()
public void visit(CacheStorage.VisitContext ctx, CacheStorage.EntryFilter f, CacheStorage.EntryVisitor v) throws Exception
CacheStoragePurgeableStorage is not
implemented, returning expired entries is a must, to support the generic purge
algorithm.
If the ExecutorService is used, the method may return immediately without
the waiting for all threads to finish. This is done by the caller, when needed.visit in interface CacheStorageExceptionpublic void updateEntryExpireTime(Object key, long _millis) throws Exception
EntryExpiryUpdateableStorageupdateEntryExpireTime in interface EntryExpiryUpdateableStorageExceptionpublic long getPutCnt()
public String toString()
public static long readCompressedLong(ByteBuffer b)
public static void writeCompressedLong(ByteBuffer b, long v)
public static int calculateCompressedLongSize(long v)
cache2k API documentation. Copyright © 2000–2015 headissue GmbH, Munich.