Class ContentCacheImpl

  • All Implemented Interfaces:
    ContentCache

    public class ContentCacheImpl
    extends java.lang.Object
    implements 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
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(java.lang.String contentUrl)
      Check to see if the content - specified by URL - exists in the cache.
      boolean contains​(Key key)
      Allows caller to perform lookup using a Key.
      static java.lang.String createNewCacheFilePath()
      Creates a relative path for a new cache file.
      void deleteFile​(java.lang.String url)
      Deletes the cached content file for the specified URL.
      java.lang.String getCacheFilePath​(java.lang.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.
      java.io.File getCacheRoot()
      Returns the directory where cache files will be written (cacheRoot).
      java.lang.String getContentUrl​(java.io.File file)
      Get a content URL from the cache - keyed by File.
      org.alfresco.service.cmr.repository.ContentReader getReader​(java.lang.String contentUrl)
      Retrieve a ContentReader for the cached content specified by URL.
      org.alfresco.service.cmr.repository.ContentWriter getWriter​(java.lang.String url)
      Retrieve a ContentWriter to write content to a cache file.
      void processFiles​(FileHandler handler)
      Ask the ContentCacheImpl to visit all the content files in the cache.
      boolean put​(java.lang.String contentUrl, org.alfresco.service.cmr.repository.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).
      void putIntoLookup​(Key key, java.lang.String value)
      Put an item in the lookup table.
      void remove​(java.lang.String contentUrl)
      Remove a cached item from the in-memory lookup table.
      void removeAll()
      Remove all items from the lookup table.
      void setCacheRoot​(java.io.File cacheRoot)
      Specify the directory where cache files will be written.
      void setMemoryStore​(org.alfresco.repo.cache.SimpleCache<Key,​java.lang.String> memoryStore)
      Configure ContentCache with a memory store.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ContentCacheImpl

        public ContentCacheImpl()
    • Method Detail

      • contains

        public boolean contains​(java.lang.String contentUrl)
        Description copied from interface: ContentCache
        Check 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:
        contains in interface ContentCache
        Parameters:
        contentUrl - String
        Returns:
        true if the URL exists in the in-memory cache. It may therefore be cached on disk.
      • contains

        public boolean contains​(Key key)
        Allows caller to perform lookup using a Key.
        Parameters:
        key - Key
        Returns:
        true if the cache contains, false otherwise.
      • putIntoLookup

        public void putIntoLookup​(Key key,
                                  java.lang.String value)
        Put an item in the lookup table.
        Parameters:
        key - Key
        value - String
      • getCacheFilePath

        public java.lang.String getCacheFilePath​(java.lang.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.
        Parameters:
        contentUrl - String
        Returns:
        cache file path
      • getContentUrl

        public java.lang.String getContentUrl​(java.io.File file)
        Get a content URL from the cache - keyed by File.
        Parameters:
        file - File
        Returns:
        String
      • getReader

        public org.alfresco.service.cmr.repository.ContentReader getReader​(java.lang.String contentUrl)
        Description copied from interface: ContentCache
        Retrieve a ContentReader for the cached content specified by URL.
        Specified by:
        getReader in interface ContentCache
        Parameters:
        contentUrl - String
        Returns:
        ContentReader
      • put

        public boolean put​(java.lang.String contentUrl,
                           org.alfresco.service.cmr.repository.ContentReader source)
        Description copied from interface: ContentCache
        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). Empty content will NOT be cached - in which case false is returned.
        Specified by:
        put in interface ContentCache
        Parameters:
        contentUrl - String
        source - ContentReader
        Returns:
        true if the content was cached, false otherwise.
      • remove

        public void remove​(java.lang.String contentUrl)
        Description copied from interface: ContentCache
        Remove 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 with ContentCache.deleteFile(String).
        Specified by:
        remove in interface ContentCache
        Parameters:
        contentUrl - String
      • removeAll

        public void removeAll()
        Remove all items from the lookup table. Cached content files are not removed.
      • deleteFile

        public void deleteFile​(java.lang.String url)
        Description copied from interface: ContentCache
        Deletes the cached content file for the specified URL. To remove the item from the lookup table also, use ContentCache.remove(String) after calling this method.
        Specified by:
        deleteFile in interface ContentCache
        Parameters:
        url - String
      • getWriter

        public org.alfresco.service.cmr.repository.ContentWriter getWriter​(java.lang.String url)
        Description copied from interface: ContentCache
        Retrieve 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:
        getWriter in interface ContentCache
        Parameters:
        url - url
        Returns:
        ContentWriter
      • createNewCacheFilePath

        public static java.lang.String 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.bin

        e.g. 2011/12/3/13/55/27d56416-bf9f-4d89-8f9e-e0a52de0a59e.bin

        Returns:
        The relative path for the new cache file.
      • setMemoryStore

        public void setMemoryStore​(org.alfresco.repo.cache.SimpleCache<Key,​java.lang.String> memoryStore)
        Configure ContentCache with a memory store.
        Parameters:
        memoryStore - the memoryStore to set
      • setCacheRoot

        public void setCacheRoot​(java.io.File cacheRoot)
        Specify the directory where cache files will be written.
        Parameters:
        cacheRoot - File
      • getCacheRoot

        public java.io.File getCacheRoot()
        Returns the directory where cache files will be written (cacheRoot).
        Specified by:
        getCacheRoot in interface ContentCache
        Returns:
        cacheRoot
      • processFiles

        public void processFiles​(FileHandler handler)
        Ask the ContentCacheImpl to visit all the content files in the cache.
        Parameters:
        handler - FileHandler