Package org.apache.naming.resources
Class ResourceCache
- java.lang.Object
-
- org.apache.naming.resources.ResourceCache
-
public class ResourceCache extends Object
Implements a special purpose cache.- Version:
- $Revision: 1.3 $
- Author:
- Remy Maucherat
-
-
Field Summary
Fields Modifier and Type Field Description protected longaccessCountNumber of accesses to the cache.protected CacheEntry[]cacheCache.protected intcacheMaxSizeMax size of resources which will have their content cached.protected intcacheSizeCurrent cache size in KB.protected longdesiredEntryAccessRatioEntry hit ratio at which an entry will never be removed from the cache.protected longhitsCountNumber of cache hits.protected intmaxAllocateIterationsMax amount of removals during a make space.protected HashMap<String,CacheEntry>notFoundCacheNot found cache.protected SecureRandomrandomRandom generator used to determine elements to free.protected intspareNotFoundEntriesSpare amount of not found entries.
-
Constructor Summary
Constructors Constructor Description ResourceCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallocate(int space)longgetAccessCount()Return the access count.intgetCacheMaxSize()Return the maximum size of the cache in KB.intgetCacheSize()Return the current cache size in KB.longgetDesiredEntryAccessRatio()Return desired entry access ratio.longgetHitsCount()Return the number of cache hits.intgetMaxAllocateIterations()Return the maximum amount of iterations during a space allocation.intgetSpareNotFoundEntries()Return the amount of spare not found entries.voidload(CacheEntry entry)CacheEntrylookup(String name)voidsetCacheMaxSize(int cacheMaxSize)Set the maximum size of the cache in KB.voidsetDesiredEntryAccessRatio(long desiredEntryAccessRatio)Set the desired entry access ratio.voidsetMaxAllocateIterations(int maxAllocateIterations)Set the maximum amount of iterations during a space allocation.voidsetSpareNotFoundEntries(int spareNotFoundEntries)Set the amount of spare not found entries.booleanunload(String name)
-
-
-
Field Detail
-
random
protected SecureRandom random
Random generator used to determine elements to free.
-
cache
protected CacheEntry[] cache
Cache. Path -> Cache entry.
-
notFoundCache
protected HashMap<String,CacheEntry> notFoundCache
Not found cache.
-
cacheMaxSize
protected int cacheMaxSize
Max size of resources which will have their content cached.
-
maxAllocateIterations
protected int maxAllocateIterations
Max amount of removals during a make space.
-
desiredEntryAccessRatio
protected long desiredEntryAccessRatio
Entry hit ratio at which an entry will never be removed from the cache. Compared with entry.access / hitsCount
-
spareNotFoundEntries
protected int spareNotFoundEntries
Spare amount of not found entries.
-
cacheSize
protected int cacheSize
Current cache size in KB.
-
accessCount
protected long accessCount
Number of accesses to the cache.
-
hitsCount
protected long hitsCount
Number of cache hits.
-
-
Method Detail
-
getAccessCount
public long getAccessCount()
Return the access count. Note: Update is not synced, so the number may not be completely accurate.
-
getCacheMaxSize
public int getCacheMaxSize()
Return the maximum size of the cache in KB.
-
setCacheMaxSize
public void setCacheMaxSize(int cacheMaxSize)
Set the maximum size of the cache in KB.
-
getCacheSize
public int getCacheSize()
Return the current cache size in KB.
-
getDesiredEntryAccessRatio
public long getDesiredEntryAccessRatio()
Return desired entry access ratio.
-
setDesiredEntryAccessRatio
public void setDesiredEntryAccessRatio(long desiredEntryAccessRatio)
Set the desired entry access ratio.
-
getHitsCount
public long getHitsCount()
Return the number of cache hits. Note: Update is not synced, so the number may not be completely accurate.
-
getMaxAllocateIterations
public int getMaxAllocateIterations()
Return the maximum amount of iterations during a space allocation.
-
setMaxAllocateIterations
public void setMaxAllocateIterations(int maxAllocateIterations)
Set the maximum amount of iterations during a space allocation.
-
getSpareNotFoundEntries
public int getSpareNotFoundEntries()
Return the amount of spare not found entries.
-
setSpareNotFoundEntries
public void setSpareNotFoundEntries(int spareNotFoundEntries)
Set the amount of spare not found entries.
-
allocate
public boolean allocate(int space)
-
lookup
public CacheEntry lookup(String name)
-
load
public void load(CacheEntry entry)
-
unload
public boolean unload(String name)
-
-