Class ContentCacheImpl
java.lang.Object
org.alfresco.repo.content.caching.ContentCacheImpl
- All Implemented Interfaces:
ContentCache
The one and only implementation of the ContentCache class. Binary content data itself is stored on disk in the location specified by
cacheRoot.
The in-memory lookup table is provided by a SimpleCache implementation.
- Author:
- Matt Ward
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThis FileContentWriter subclass allows for the temp cache file to be renamed to a cache file proper, e.g filename.tmp becomes filename.binprotected static class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanCheck to see if the content - specified by URL - exists in the cache.booleanAllows caller to perform lookup using aKey.static StringCreates a relative path for a new cache file.voiddeleteFile(String url) Deletes the cached content file for the specified URL.getCacheFilePath(String contentUrl) Get the path of a cache file for the given content URL - will return null if there is no entry in the cache for the specified URL.Returns the directory where cache files will be written (cacheRoot).getContentUrl(File file) Get a content URL from the cache - keyed by File.Retrieve a ContentReader for the cached content specified by URL.Retrieve a ContentWriter to write content to a cache file.voidprocessFiles(FileHandler handler) Ask the ContentCacheImpl to visit all the content files in the cache.booleanput(String contentUrl, ContentReader source) Put an item into cache - this will populate both a disk file (with content) and the in-memory lookup table (with the URL and cache file location).voidputIntoLookup(Key key, String value) Put an item in the lookup table.voidRemove a cached item from the in-memory lookup table.voidRemove all items from the lookup table.voidsetCacheRoot(File cacheRoot) Specify the directory where cache files will be written.voidsetMemoryStore(SimpleCache<Key, String> memoryStore) Configure ContentCache with a memory store.
-
Constructor Details
-
ContentCacheImpl
public ContentCacheImpl()
-
-
Method Details
-
contains
Description copied from interface:ContentCacheCheck to see if the content - specified by URL - exists in the cache.Note that just because the in-memory cache has a record of the content item having been placed into the cache, it does not mean that the disk item is guaranteed to be there. The temp file clean-up process, for example, may have removed it.
- Specified by:
containsin interfaceContentCache- Parameters:
contentUrl- String- Returns:
- true if the URL exists in the in-memory cache. It may therefore be cached on disk.
-
contains
Allows caller to perform lookup using aKey.- Parameters:
key- Key- Returns:
- true if the cache contains, false otherwise.
-
putIntoLookup
Put an item in the lookup table.- Parameters:
key- Keyvalue- String
-
getCacheFilePath
Get the path of a cache file for the given content URL - will return null if there is no entry in the cache for the specified URL.- Parameters:
contentUrl- String- Returns:
- cache file path
-
getContentUrl
Get a content URL from the cache - keyed by File.- Parameters:
file- File- Returns:
- String
-
getReader
Description copied from interface:ContentCacheRetrieve a ContentReader for the cached content specified by URL.- Specified by:
getReaderin interfaceContentCache- Parameters:
contentUrl- String- Returns:
- ContentReader
-
put
Description copied from interface:ContentCachePut an item into cache - this will populate both a disk file (with content) and the in-memory lookup table (with the URL and cache file location). Empty content will NOT be cached - in which case false is returned.- Specified by:
putin interfaceContentCache- Parameters:
contentUrl- Stringsource- ContentReader- Returns:
- true if the content was cached, false otherwise.
-
remove
Description copied from interface:ContentCacheRemove a cached item from the in-memory lookup table. Implementation should not remove the actual cached content (file) - this should be left to the clean-up process or can be deleted withContentCache.deleteFile(String).- Specified by:
removein interfaceContentCache- Parameters:
contentUrl- String
-
removeAll
public void removeAll()Remove all items from the lookup table. Cached content files are not removed. -
deleteFile
Description copied from interface:ContentCacheDeletes the cached content file for the specified URL. To remove the item from the lookup table also, useContentCache.remove(String)after calling this method.- Specified by:
deleteFilein interfaceContentCache- Parameters:
url- String
-
getWriter
Description copied from interface:ContentCacheRetrieve a ContentWriter to write content to a cache file. Upon closing the stream a listener will add the new content file to the in-memory lookup table.- Specified by:
getWriterin interfaceContentCache- Parameters:
url- url- Returns:
- ContentWriter
-
createNewCacheFilePath
Creates a relative path for a new cache file. The path is based upon the current date/time: year/month/day/hour/minute/guid.bine.g. 2011/12/3/13/55/27d56416-bf9f-4d89-8f9e-e0a52de0a59e.bin
- Returns:
- The relative path for the new cache file.
-
setMemoryStore
Configure ContentCache with a memory store.- Parameters:
memoryStore- the memoryStore to set
-
setCacheRoot
Specify the directory where cache files will be written.- Parameters:
cacheRoot- File
-
getCacheRoot
Returns the directory where cache files will be written (cacheRoot).- Specified by:
getCacheRootin interfaceContentCache- Returns:
- cacheRoot
-
processFiles
Ask the ContentCacheImpl to visit all the content files in the cache.- Parameters:
handler- FileHandler
-