Still in development
- Add jitpack in your root build.gradle at the end of repositories
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile "com.github.mskn73:kache:${kacheVersion}"
}
- Implement the Kacheable interface for your class
internal inner class MyObject(override val key: String) : Kacheable
If you want to specifies the expiration time, annotates the class with `KacheLife:
@KacheLife(expiresTime = (60 * 1000).toLong())
internal inner class MyObject(override val key: String) : Kacheable
- Save and retrieve the object:
//Instantiate Kache
val k = Kache(applicationContext, cacheDir.toString())
//Save data
k.put(MyObject("fake@mail.com"))
//Get the data
val myKachedObject = k.get(MyObject::class.java, "fake@mail.com") as Kacheable
- Implement the Kacheable interface for your class
class MyObject implements Kacheable {
private final String mail;
public MyObject(String mail) {
this.mail = mail;
}
@NotNull @Override public String getKey() {
return mail;
}
}
If you want to specifies the expiration time, annotates the class with `KacheLife:
@KacheLife(expiresTime = 60 * 1000)
class MyObject implements Kacheable {
private final String mail;
public MyObject(String mail) {
this.mail = mail;
}
@NotNull @Override public String getKey() {
return mail;
}
}
- Save and retrieve the object:
//Instantiate Kache
Kache k = new Kache(getApplicationContext(), getCacheDir().toString());
//Save data
k.put(new MyObject("fake@mail.com"));
//Get the data
Kacheable myKachedObject = (Kacheable) k.get(MyObject.class, "fake@mail.com");