|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectinfo.sswap.impl.empire.io.ModelCache
public class ModelCache
A cache for Jena models. This class is thread safe and can be used by concurrently downloading threads.
Nested Class Summary | |
---|---|
(package private) static class |
ModelCache.MemoryCacheEntry
|
Field Summary | |
---|---|
private java.util.Map<java.lang.String,java.lang.ref.SoftReference<ModelCache.MemoryCacheEntry>> |
cache
Map of model URIs to Jena Models |
private java.lang.String |
cacheDirName
Cache directory |
private boolean |
cacheEnabled
Flag whether any (memory or disk) caching is enabled |
private java.lang.String |
cacheIndexFile
Cache index file |
private static long |
defaultEntryTTL
Default time-to-live (TTL). |
private boolean |
diskCacheEnabled
Flag whether persistent cache is enabled or disabled. |
private long |
entryTTL
The time-to-live (TTL) for entries in ms. |
private static java.lang.String |
FILE_PREFIX
|
private java.util.Properties |
locationMap
Cache contents mapping URIs to local file paths. |
private static org.apache.log4j.Logger |
LOGGER
|
private long |
negativeEntryTTL
|
private java.util.List<java.lang.String> |
negativeUriQueue
|
private java.util.List<java.lang.String> |
positiveUriQueue
The queue of URIs in the order they were added (new caches are always added at the end, and the expired caches are removed from the front). |
private java.util.Map<java.lang.String,java.lang.Long> |
storageNegativeTimes
|
private java.util.Map<java.lang.String,java.lang.Long> |
storagePositiveTimes
Map of model URIs to the time when they were stored in this cache (to properly detect expired caches). |
Constructor Summary | |
---|---|
ModelCache()
Creates an empty cache |
|
ModelCache(long entryTTL,
long negativeEntryTTL)
Creates an empty cache with a time-to-live TTL. |
|
ModelCache(long entryTTL,
long negativeEntryTTL,
boolean diskCacheEnabled)
|
Method Summary | |
---|---|
void |
clear()
Removes all entries from the cache. |
private void |
clearDisk()
|
private void |
clearMemory()
|
boolean |
containsModel(java.lang.String uri)
Deprecated. The use of this method may cause problems with TTL. (It is possible that this method would report a model as existing in this cache, but then the model's TTL would be exceeded before getModel() is called, which would cause getModel() to return null) |
private static long |
getConfigEntryTTL()
|
private static long |
getConfigNegativeEntryTTL()
|
java.io.File |
getDirectory()
Gets the directory where the files are stored in the cache. |
private java.util.Properties |
getLocationMap()
|
com.hp.hpl.jena.rdf.model.Model |
getModel(java.lang.String uri)
Gets a copy of a model that is already in the cache. |
private com.hp.hpl.jena.rdf.model.Model |
getModelFromDisk(java.lang.String uri)
|
private com.hp.hpl.jena.rdf.model.Model |
getModelFromMemory(java.lang.String uri)
|
long |
getNegativeTimeToLive()
|
long |
getTimeToLive()
Gets the time-to-live (TTL) for entries. |
private void |
initDiskCache()
|
private boolean |
isDiskEntryExpired(java.lang.String fileURL)
|
private boolean |
isExpired(java.lang.String uri,
boolean negative)
Checks whether an entry is expired. |
private void |
removeExpiredData()
Removes all entries that are expired |
private void |
removeExpiredData(boolean negative)
|
void |
setAsInaccessible(java.lang.String uri)
|
void |
setModel(java.lang.String uri,
com.hp.hpl.jena.rdf.model.Model model)
Stores a copy of a model in the cache. |
private void |
setModel(java.lang.String uri,
com.hp.hpl.jena.rdf.model.Model model,
boolean negative)
|
void |
setNegativeTimeToLive(long negativeEntryTTL)
|
void |
setTimeToLive(long entryTTL)
Sets the time-to-live (in milliseconds) for entries in this cache. |
private void |
storeInMemory(java.lang.String uri,
com.hp.hpl.jena.rdf.model.Model model,
boolean negative)
|
private void |
storeOnDisk(java.lang.String uri,
com.hp.hpl.jena.rdf.model.Model model)
|
private static java.io.File |
toFile(java.lang.String fileURL)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final org.apache.log4j.Logger LOGGER
private static final java.lang.String FILE_PREFIX
private java.lang.String cacheDirName
private java.lang.String cacheIndexFile
private java.util.Properties locationMap
private java.util.Map<java.lang.String,java.lang.ref.SoftReference<ModelCache.MemoryCacheEntry>> cache
private java.util.Map<java.lang.String,java.lang.Long> storagePositiveTimes
private java.util.Map<java.lang.String,java.lang.Long> storageNegativeTimes
private java.util.List<java.lang.String> positiveUriQueue
private java.util.List<java.lang.String> negativeUriQueue
private static final long defaultEntryTTL
entryTTL
,
Constant Field Valuesprivate long entryTTL
private long negativeEntryTTL
private boolean diskCacheEnabled
private boolean cacheEnabled
Constructor Detail |
---|
public ModelCache()
public ModelCache(long entryTTL, long negativeEntryTTL)
entryTTL
- time-to-live for a URI cache, in milliseconds, before it is
considered stale and removed from the cachegetTimeToLive()
public ModelCache(long entryTTL, long negativeEntryTTL, boolean diskCacheEnabled)
Method Detail |
---|
private void initDiskCache()
private java.util.Properties getLocationMap()
public long getTimeToLive()
getTimeToLive
in interface Cache
public void setTimeToLive(long entryTTL)
setTimeToLive
in interface Cache
entryTTL
- the new TTL in mspublic long getNegativeTimeToLive()
public void setNegativeTimeToLive(long negativeEntryTTL)
private static java.io.File toFile(java.lang.String fileURL)
private void clearMemory()
private void clearDisk()
public void clear()
Cache
clear
in interface Cache
public java.io.File getDirectory()
getDirectory
in interface Cache
public boolean containsModel(java.lang.String uri)
uri
- the URI of the model
public com.hp.hpl.jena.rdf.model.Model getModel(java.lang.String uri)
uri
- the URI of the model
private com.hp.hpl.jena.rdf.model.Model getModelFromMemory(java.lang.String uri)
private boolean isDiskEntryExpired(java.lang.String fileURL)
private com.hp.hpl.jena.rdf.model.Model getModelFromDisk(java.lang.String uri)
public void setModel(java.lang.String uri, com.hp.hpl.jena.rdf.model.Model model)
uri
- the URI of the modelmodel
- the model whose copy will be cached.private void setModel(java.lang.String uri, com.hp.hpl.jena.rdf.model.Model model, boolean negative)
public void setAsInaccessible(java.lang.String uri)
private void storeInMemory(java.lang.String uri, com.hp.hpl.jena.rdf.model.Model model, boolean negative)
private void storeOnDisk(java.lang.String uri, com.hp.hpl.jena.rdf.model.Model model)
private boolean isExpired(java.lang.String uri, boolean negative)
uri
- the URI of the entry to check for expiration
private void removeExpiredData()
private void removeExpiredData(boolean negative)
private static long getConfigEntryTTL()
private static long getConfigNegativeEntryTTL()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |