Package de.dlr.proseo.storagemgr.cache
Klasse FileCache
java.lang.Object
de.dlr.proseo.storagemgr.cache.FileCache
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
-
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibung(Package privat) void
clear()
Clears all cache elements only (files remain on disk)boolean
containsKey
(String pathKey) Checks if the cache contains the path.(Package privat) void
Deletes a cache file and logically connected auxiliary files from the disk(Package privat) void
deleteEmptyDirectoriesToTop
(String directoryToDelete) Deletes empty directories recursively in the direction of root(Package privat) FileInfo
Gets the path key from file cache(Package privat) String
getAccessedPath
(String path) Gets the accessed path of the file(Package privat) static String
Gets the file prefix for accessed filesgetCacheFileStatus
(String path) Returns a status of the cache file(Package privat) Instant
getFileAccessed
(String path) Returns the last accessed time stamp of the file(Package privat) Long
getFileSize
(String path) Returns the file size in bytesstatic FileCache
Instance of file cacheGets the map cache(Package privat) String
getPathFromAccessed
(String accessedPath) Gets the path to file from accessed path(Package privat) String
getPathFromStatus
(String statusPath) Gets a cache path from a status path(Package privat) String
getStatusPath
(String path) Gets the path of the status file(Package privat) String
getTemporaryPath
(String path) Gets the path of the temporary filestatic String
Gets temporary prefix of the filevoid
Puts the new element to map.(Package privat) void
putFilesToCache
(String path) Puts files to cache, removes accessed prefix files without files, removes temporary prefix files(Package privat) void
putWithoutUpdateAccessedPrefixFile
(String pathKey) Puts the file to map without update accessed prefix file.(Package privat) void
Removes cache element, cache file and auxiliary files(Package privat) void
Removes all cache elements and their connected files and accessed files from diskvoid
setCacheFileStatus
(String pathKey, CacheFileStatus status) Sets the status of a cache file.(Package privat) void
Clears the cache only (without deleting of files), sets the cache path and puts files in cache(Package privat) int
size()
Gives the number of elements in cache
-
Konstruktordetails
-
FileCache
public FileCache()
-
-
Methodendetails
-
getInstance
Instance of file cache- Gibt zurück:
- file cache singleton
-
put
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
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
Gets temporary prefix of the file- Gibt zurück:
- temporary prefix of the file
-
getCacheFileStatus
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
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
Clears the cache only (without deleting of files), sets the cache path and puts files in cache- Parameter:
pathKey
- The Cache Path
-
get
Gets the path key from file cache- Parameter:
pathKey
- Path to the cache file- Gibt zurück:
-
remove
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
Gets the map cache- Gibt zurück:
- map cache
-
getAccessedPrefix
Gets the file prefix for accessed files- Gibt zurück:
- the file prefix
-
putFilesToCache
Puts files to cache, removes accessed prefix files without files, removes temporary prefix files- Parameter:
path
- Path to files
-
putWithoutUpdateAccessedPrefixFile
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
Deletes a cache file and logically connected auxiliary files from the disk- Parameter:
path
- full path to the cache file
-
deleteEmptyDirectoriesToTop
Deletes empty directories recursively in the direction of root- Parameter:
directoryToDelete
- the path to the directory
-
getFileSize
Returns the file size in bytes- Parameter:
path
- The full path to file- Gibt zurück:
- the file size
-
getFileAccessed
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
Gets the accessed path of the file- Parameter:
path
- The full path to the file- Gibt zurück:
- accessed path
-
getStatusPath
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
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
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
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
-