Class FileSystemCache

java.lang.Object
de.umass.lastfm.cache.Cache
de.umass.lastfm.cache.FileSystemCache
All Implemented Interfaces:
ScrobbleCache

public class FileSystemCache extends Cache implements ScrobbleCache
Standard Cache implementation which is used by default by the Caller class. This implementation caches all responses in the file system. In addition to the raw responses it stores a .meta file which contains the expiration date for the specified request.
Author:
Janni Kovacs
  • Constructor Details

    • FileSystemCache

      public FileSystemCache()
    • FileSystemCache

      public FileSystemCache(File cacheDir)
  • Method Details

    • contains

      public boolean contains(String cacheEntryName)
      Description copied from class: Cache
      Checks if the cache contains an entry with the given name.
      Specified by:
      contains in class Cache
      Parameters:
      cacheEntryName - An entry name
      Returns:
      true if the cache contains this entry
    • remove

      public void remove(String cacheEntryName)
      Description copied from class: Cache
      Removes the specified entry from the cache if available. Does nothing if no such entry is available.
      Specified by:
      remove in class Cache
      Parameters:
      cacheEntryName - An entry name
    • isExpired

      public boolean isExpired(String cacheEntryName)
      Description copied from class: Cache
      Checks if the specified entry is expired.
      Specified by:
      isExpired in class Cache
      Parameters:
      cacheEntryName - An entry name
      Returns:
      true if the entry is expired
    • clear

      public void clear()
      Description copied from class: Cache
      Clears the cache by effectively removing all cached data.
      Specified by:
      clear in class Cache
    • load

      public InputStream load(String cacheEntryName)
      Description copied from class: Cache
      Loads the specified entry from the cache and returns an InputStream to be read from. Returns null if the cache does not contain the specified cacheEntryName.
      Specified by:
      load in class Cache
      Parameters:
      cacheEntryName - An entry name
      Returns:
      an InputStream or null
    • store

      public void store(String cacheEntryName, InputStream inputStream, long expirationDate)
      Description copied from class: Cache
      Stores a request in the cache.
      Specified by:
      store in class Cache
      Parameters:
      cacheEntryName - The entry name to be stored to
      inputStream - An InputStream containing the data to be cached
      expirationDate - The date of expiration represented in milliseconds since 1.1.1970
    • cacheScrobble

      public void cacheScrobble(Collection<SubmissionData> submissions)
      Description copied from interface: ScrobbleCache
      Caches a collection of SubmissionData.
      Specified by:
      cacheScrobble in interface ScrobbleCache
      Parameters:
      submissions - The submissions
    • cacheScrobble

      public void cacheScrobble(SubmissionData... submissions)
      Description copied from interface: ScrobbleCache
      Caches one or more SubmissionData.
      Specified by:
      cacheScrobble in interface ScrobbleCache
      Parameters:
      submissions - The submissions
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: ScrobbleCache
      Checks if the cache contains any scrobbles.
      Specified by:
      isEmpty in interface ScrobbleCache
      Returns:
      true if this cache is empty
    • scrobble

      public void scrobble(Scrobbler scrobbler) throws IOException
      Description copied from interface: ScrobbleCache
      Tries to scrobble all cached scrobbles. If it succeeds the cache will be empty afterwards. If this method fails an IOException is thrown and no entries are removed from the cache.
      Specified by:
      scrobble in interface ScrobbleCache
      Parameters:
      scrobbler - A Scrobbler instance
      Throws:
      IOException - on I/O errors
    • clearScrobbleCache

      public void clearScrobbleCache()
      Description copied from interface: ScrobbleCache
      Clears all cached scrobbles from this cache.
      Specified by:
      clearScrobbleCache in interface ScrobbleCache