Class FileCacheProvider
- java.lang.Object
-
- com.deviceatlas.cloud.deviceidentification.cacheprovider.FileCacheProvider
-
- All Implemented Interfaces:
CacheProvider
public class FileCacheProvider extends java.lang.Object implements CacheProvider
File cache provider.
-
-
Constructor Summary
Constructors Constructor Description FileCacheProvider()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Entirely clear the cache contentvoid
definePaths()
Define the root path<T> T
get(java.lang.String key)
Getting an entry on the cachejava.nio.file.Path
getCachePath(java.lang.String key)
Returns the path from the given keyjava.util.List<java.lang.String>
getKeys()
Returns all keys from a given cache<T> void
lockAndSet(java.lang.String key, T entry)
Applies a lock to a cache's filevoid
parseConfig(java.io.BufferedReader br)
Parses the config filevoid
remove(java.lang.String key)
Removes an entry in the cache<T> void
set(java.lang.String key, T entry)
Adding an entry to the cachevoid
setCacheFileEntry(java.io.File current, java.nio.file.Path path)
Sets a file cache entryvoid
setExpiry(int expiry)
Reconfigure the expiry aftervoid
shutdown()
No shutdown operation for this class
-
-
-
Method Detail
-
parseConfig
public void parseConfig(java.io.BufferedReader br) throws java.io.IOException
Parses the config file- Parameters:
br
-- Throws:
java.io.IOException
-
definePaths
public void definePaths()
Define the root path
-
setCacheFileEntry
public void setCacheFileEntry(java.io.File current, java.nio.file.Path path)
Sets a file cache entry- Parameters:
current
-path
-
-
getCachePath
public java.nio.file.Path getCachePath(java.lang.String key) throws java.io.IOException
Returns the path from the given key- Parameters:
key
-- Returns:
- Path
- Throws:
java.io.IOException
-
get
public <T> T get(java.lang.String key) throws CacheException
Description copied from interface:CacheProvider
Getting an entry on the cache- Specified by:
get
in interfaceCacheProvider
- Type Parameters:
T
- cache entry- Parameters:
key
- key of the cache entry- Returns:
- Object
- Throws:
CacheException
- when there is cache issues getting by key
-
lockAndSet
public <T> void lockAndSet(java.lang.String key, T entry) throws CacheException
Applies a lock to a cache's file- Parameters:
key
-entry
-- Throws:
CacheException
-
set
public <T> void set(java.lang.String key, T entry) throws CacheException
Description copied from interface:CacheProvider
Adding an entry to the cache- Specified by:
set
in interfaceCacheProvider
- Type Parameters:
T
- cache entry- Parameters:
key
- key of the cache entryentry
- cache entry- Throws:
CacheException
- when there is cache issues setting an element
-
remove
public void remove(java.lang.String key) throws CacheException
Description copied from interface:CacheProvider
Removes an entry in the cache- Specified by:
remove
in interfaceCacheProvider
- Parameters:
key
- key of the cache entry- Throws:
CacheException
- when there is cache issues removing an entry
-
clear
public void clear()
Description copied from interface:CacheProvider
Entirely clear the cache content- Specified by:
clear
in interfaceCacheProvider
-
shutdown
public void shutdown()
No shutdown operation for this class- Specified by:
shutdown
in interfaceCacheProvider
-
getKeys
public java.util.List<java.lang.String> getKeys()
Description copied from interface:CacheProvider
Returns all keys from a given cache- Specified by:
getKeys
in interfaceCacheProvider
- Returns:
- List
-
setExpiry
public void setExpiry(int expiry)
Description copied from interface:CacheProvider
Reconfigure the expiry after- Specified by:
setExpiry
in interfaceCacheProvider
- Parameters:
expiry
- cache time life in minutes
-
-