Package com.naver.ads.persistence.cache
Class DiskLruCache
-
- All Implemented Interfaces:
public abstract class DiskLruCache<T extends Object>A disk-based LRU cache for storing data.
-
-
Field Summary
Fields Modifier and Type Field Description private final FilecacheDirectoryprivate final LongcacheSizeLimit
-
Constructor Summary
Constructors Constructor Description DiskLruCache(String cacheDir, Long maxSize, Float diskSpaceAllocationRatio)
-
Method Summary
Modifier and Type Method Description final FilegetCacheDirectory()The directory where the cache files are stored. final LonggetCacheSizeLimit()The effective cache size limit in bytes. final Tget(String key)Get data from disk cache abstract TreadFromFile(File file)final Unitput(String key, T value)Put data to disk cache abstract UnitwriteToFile(File file, T value)final Unitremove(String key)Remove data from cache final Unitclear()Clear all cached files final Longsize()Get current cache size in bytes -
-
Method Detail
-
getCacheDirectory
final File getCacheDirectory()
The directory where the cache files are stored.
-
getCacheSizeLimit
final Long getCacheSizeLimit()
The effective cache size limit in bytes.
This value is calculated as diskSpaceAllocationRatio of available disk space, constrained to be at most maxSize. If calculation fails, defaults to maxSize.
-
get
@WorkerThread() final T get(String key)
Get data from disk cache
- Parameters:
key- cache key- Returns:
cached data or null if not found
-
readFromFile
abstract T readFromFile(File file)
-
put
@WorkerThread() final Unit put(String key, T value)
Put data to disk cache
- Parameters:
key- cache keyvalue- data to cache
-
writeToFile
abstract Unit writeToFile(File file, T value)
-
remove
@WorkerThread() final Unit remove(String key)
Remove data from cache
- Parameters:
key- cache key
-
clear
@WorkerThread() final Unit clear()
Clear all cached files
-
-
-
-