Klasse FileCache

java.lang.Object
de.dlr.proseo.storagemgr.cache.FileCache

@Component public class FileCache extends Object
File cache for managing files in the cache storage. Features: 1) saves the time stamp of the last access of the cache file; 2) contains the status of the cache file, which can be changed. The status file with the status "not exists" can exists alone or together with the cache file. The existence of status file "not exists" shows, that copying failed and the status file "not exists" together with the cache file (if exists) will be deleted after the new initialization of the cache. In case of new copy attempt they will be overwritten. In case of calling put() with the existing cache file, status will be changed to "ready" 3) uses the possibility to save in the cache also "temporary" files (temporary file is a file, which has not yet been copied to the cache. After copying it will be renamed to the cache file. In case of unsuccessful copying a temporary file will be deleted) Information about some public methods: The method put(fullPath): - puts the file to the cache; - sets the file status "READY"; - sets/updates the last accessed record; - cleans the cache if there is not enough free space - deletes the file physically if it is a temporary file The method containsKey(fullPath): - checks if the path is in the cache. Only cache paths with the status "READY" are visible - removes the cache path from the cache if the physical file does not exist anymore - if the file is in the cache, updates the time stamp of the last access calling put()
Autor:
Denys Chaykovskiy
  • Konstruktordetails

    • FileCache

      public FileCache()
  • Methodendetails

    • getInstance

      public static FileCache getInstance()
      Instance of file cache
      Gibt zurück:
      file cache singleton
    • put

      public void put(String pathKey)
      Puts the new element to map. If element exists, it will be overwritten. Removes the file if it is temporary file (not a cache file). Calls deleteLRU before adding the file to cache to clean free space if needed. Set the status = "ready" and updates the last access record of the cache file.
      Parameter:
      pathKey - the full cache file path as a key
    • containsKey

      public boolean containsKey(String pathKey)
      Checks if the cache contains the path. If not - returns false. If the physical file does not exits anymore - deletes the path from the cache. Returns true if the path is available in the cache and also updates the file record of the last access calling put() method
      Parameter:
      pathKey - File path as key
      Gibt zurück:
      true if pathkey is in file cache
    • getTemporaryPrefix

      public static String getTemporaryPrefix()
      Gets temporary prefix of the file
      Gibt zurück:
      temporary prefix of the file
    • getCacheFileStatus

      public CacheFileStatus getCacheFileStatus(String path)
      Returns a status of the cache file
      Parameter:
      path - The full path to the cache file
      Gibt zurück:
      a status of the cache file
    • setCacheFileStatus

      public void setCacheFileStatus(String pathKey, CacheFileStatus status)
      Sets the status of a cache file. The pathKey must be an existing cache file, the exception is for "not exists" cache file status.
      Parameter:
      pathKey - File path as key
    • setPath

      void setPath(String pathKey)
      Clears the cache only (without deleting of files), sets the cache path and puts files in cache
      Parameter:
      pathKey - The Cache Path
    • get

      FileInfo get(String pathKey)
      Gets the path key from file cache
      Parameter:
      pathKey - Path to the cache file
      Gibt zurück:
    • remove

      void remove(String pathKey)
      Removes cache element, cache file and auxiliary files
      Parameter:
      pathKey - Path to file
    • clear

      void clear()
      Clears all cache elements only (files remain on disk)
    • removeAll

      void removeAll()
      Removes all cache elements and their connected files and accessed files from disk
    • size

      int size()
      Gives the number of elements in cache
      Gibt zurück:
      number of elements in cache
    • getMapCache

      Map<String,FileInfo> getMapCache()
      Gets the map cache
      Gibt zurück:
      map cache
    • getAccessedPrefix

      static String getAccessedPrefix()
      Gets the file prefix for accessed files
      Gibt zurück:
      the file prefix
    • putFilesToCache

      void putFilesToCache(String path)
      Puts files to cache, removes accessed prefix files without files, removes temporary prefix files
      Parameter:
      path - Path to files
    • putWithoutUpdateAccessedPrefixFile

      void putWithoutUpdateAccessedPrefixFile(String pathKey)
      Puts the file to map without update accessed prefix file. If element exists, it will be overwritten.
      Parameter:
      pathKey - File path as a key
    • deleteCacheFileAndAuxPrefixFiles

      void deleteCacheFileAndAuxPrefixFiles(String path)
      Deletes a cache file and logically connected auxiliary files from the disk
      Parameter:
      path - full path to the cache file
    • deleteEmptyDirectoriesToTop

      void deleteEmptyDirectoriesToTop(String directoryToDelete)
      Deletes empty directories recursively in the direction of root
      Parameter:
      directoryToDelete - the path to the directory
    • getFileSize

      Long getFileSize(String path)
      Returns the file size in bytes
      Parameter:
      path - The full path to file
      Gibt zurück:
      the file size
    • getFileAccessed

      Instant getFileAccessed(String path)
      Returns the last accessed time stamp of the file
      Parameter:
      path - The full path to the file
      Gibt zurück:
      time stamp of last accessed
    • getAccessedPath

      String getAccessedPath(String path)
      Gets the accessed path of the file
      Parameter:
      path - The full path to the file
      Gibt zurück:
      accessed path
    • getStatusPath

      String getStatusPath(String path)
      Gets the path of the status file
      Parameter:
      path - The full path to the cache file
      Gibt zurück:
      the path to the status file of the cache file
    • getTemporaryPath

      String getTemporaryPath(String path)
      Gets the path of the temporary file
      Parameter:
      path - The full path to the cache file
      Gibt zurück:
      the path to the temporary file of the cache file
    • getPathFromAccessed

      String getPathFromAccessed(String accessedPath)
      Gets the path to file from accessed path
      Parameter:
      accessed - Path accessed Path to the file
      Gibt zurück:
      the full path to file
    • getPathFromStatus

      String getPathFromStatus(String statusPath)
      Gets a cache path from a status path
      Parameter:
      status - Path status Path to the file
      Gibt zurück:
      the full path to cache file