Skip to content

Latest commit

 

History

History
64 lines (47 loc) · 1.65 KB

README.md

File metadata and controls

64 lines (47 loc) · 1.65 KB

ObjectCache

Platform Build Status Jitpack

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.

Install

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'
}

Usage

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);

License

ObjectCache is available under the MIT license. See the LICENSE file for more info.