Class DefaultCockpitResourceCache
- java.lang.Object
-
- com.hybris.cockpitng.core.persistence.packaging.impl.DefaultCockpitResourceCache
-
- All Implemented Interfaces:
CockpitResourceCache,Resettable
public class DefaultCockpitResourceCache extends java.lang.Object implements CockpitResourceCache
Default CockpitResourceCache implementation. Uses aConcurrentHashMapfor caching andReentrantReadWriteLockfor handling concurrent access.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCOCKPITNG_RESOURCELOADER_RESOURCECACHE_MAXENTRYSIZE
-
Constructor Summary
Constructors Constructor Description DefaultCockpitResourceCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]addResourceToCache(java.lang.String uuid, byte[] resource)Adds a chunk of bytes to the cache.longgetAverageEntrySize()Returns the average size (in bytes) of all entries.protected CockpitPropertiesgetCockpitProperties()java.util.Collection<java.lang.String>getKeys()Returns the keys for the current entries.longgetMaxEntrySize()byte[]getResourceAsBytes(java.lang.String uuid)Gets the resource for the given key, if present in cache.longgetSize()Returns the size (in bytes) of all entries in the cache.protected longinitMaxEntrySize()voidreset()Removes all elements from the cache.voidsetCockpitProperties(CockpitProperties cockpitProperties)voidsetMaxEntrySize(long maxEntrySize)
-
-
-
Field Detail
-
COCKPITNG_RESOURCELOADER_RESOURCECACHE_MAXENTRYSIZE
public static final java.lang.String COCKPITNG_RESOURCELOADER_RESOURCECACHE_MAXENTRYSIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getResourceAsBytes
public byte[] getResourceAsBytes(java.lang.String uuid)
Description copied from interface:CockpitResourceCacheGets the resource for the given key, if present in cache.- Specified by:
getResourceAsBytesin interfaceCockpitResourceCache- Returns:
- The cached byte array, or null, if not in cache.
-
addResourceToCache
public byte[] addResourceToCache(java.lang.String uuid, byte[] resource)Description copied from interface:CockpitResourceCacheAdds a chunk of bytes to the cache.- Specified by:
addResourceToCachein interfaceCockpitResourceCache- Parameters:
uuid- The unique key for the resource, usually an uri.resource- The resource to add as byte array.- Returns:
- The passed resource, for convenience reasons.
-
reset
public void reset()
Description copied from interface:CockpitResourceCacheRemoves all elements from the cache.- Specified by:
resetin interfaceCockpitResourceCache- Specified by:
resetin interfaceResettable
-
getSize
public long getSize()
Description copied from interface:CockpitResourceCacheReturns the size (in bytes) of all entries in the cache.- Specified by:
getSizein interfaceCockpitResourceCache
-
getAverageEntrySize
public long getAverageEntrySize()
Description copied from interface:CockpitResourceCacheReturns the average size (in bytes) of all entries.- Specified by:
getAverageEntrySizein interfaceCockpitResourceCache
-
getKeys
public java.util.Collection<java.lang.String> getKeys()
Description copied from interface:CockpitResourceCacheReturns the keys for the current entries.- Specified by:
getKeysin interfaceCockpitResourceCache
-
getMaxEntrySize
public long getMaxEntrySize()
-
initMaxEntrySize
protected long initMaxEntrySize()
-
setMaxEntrySize
public void setMaxEntrySize(long maxEntrySize)
-
getCockpitProperties
protected CockpitProperties getCockpitProperties()
-
setCockpitProperties
public void setCockpitProperties(CockpitProperties cockpitProperties)
-
-