Interface ContentCache

All Known Implementing Classes:
ContentCacheImpl

public interface ContentCache
A cache designed to operate on content and split between memory and disk. The binary content data itself is stored on disk but the references to those files are stored in memory.
Author:
Matt Ward
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(String contentUrl)
    Check to see if the content - specified by URL - exists in the cache.
    void
    Deletes the cached content file for the specified URL.
    Returns the location where cache files will be written (cacheRoot) - implementation dependant and may be null.
    getReader(String contentUrl)
    Retrieve a ContentReader for the cached content specified by URL.
    Retrieve a ContentWriter to write content to a cache file.
    boolean
    put(String contentUrl, ContentReader reader)
    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
    remove(String contentUrl)
    Remove a cached item from the in-memory lookup table.
  • Method Details

    • getCacheRoot

      File getCacheRoot()
      Returns the location where cache files will be written (cacheRoot) - implementation dependant and may be null.
      Returns:
      cacheRoot
    • contains

      boolean contains(String contentUrl)
      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.

      Parameters:
      contentUrl - String
      Returns:
      true if the URL exists in the in-memory cache. It may therefore be cached on disk.
    • getReader

      ContentReader getReader(String contentUrl)
      Retrieve a ContentReader for the cached content specified by URL.
      Parameters:
      contentUrl - String
      Returns:
      ContentReader
      Throws:
      CacheMissException - If the cache does not contain the specified content.
    • put

      boolean put(String contentUrl, ContentReader reader)
      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.
      Parameters:
      contentUrl - String
      reader - ContentReader
      Returns:
      true if the content was cached, false otherwise.
    • remove

      void remove(String contentUrl)
      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 deleteFile(String).
      Parameters:
      contentUrl - String
    • deleteFile

      void deleteFile(String url)
      Deletes the cached content file for the specified URL. To remove the item from the lookup table also, use remove(String) after calling this method.
      Parameters:
      url - String
    • getWriter

      ContentWriter getWriter(String url)
      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.
      Parameters:
      url - url
      Returns:
      ContentWriter