A simple means of storing Objects
in Cache.
It uses gson internally to serialize and de-serialize Objects
. Its built on top of the awesome DiskLruCache.
DiskLruCache has been extended to support explicit eviction of entries based on an expiry.
Note: This implementation specifically targets Android compatibility.
Add jitpack to your root build.gradle
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Add the dependency
dependencies {
compile 'com.github.myntra:ObjectCache:1.0.0'
}
Get Instance
Get an instance of ObjectCache. Pass in a cacheDir
(File
) a folderName
(String
) along with the appVersion
.
ObjectCache.cacheInstance(cacheDir, folder, appVersion);
or
ObjectCache.defaultCache(cacheDir, appVersion);
Write
ObjectCache.cacheInstance(cacheDir, folder, appVersion).write(key, object, expiry);
Fetch
Will return null, if the object has expired
ObjectCache.cacheInstance(cacheDir, folder, appVersion).fetch(key, Class.class);
Fetch Even if Expired
ObjectCache.cacheInstance(cacheDir, folder, appVersion).fetchEvenIfExpired(key, Class.class);
ObjectCache is available under the MIT license. See the LICENSE file for more info.