ExpiryDB is a lightweight Android library that provides storage operations with expiry time for objects using the Paper library. It allows you to store and retrieve objects with an expiry time, automatically handling the expiration of stored objects.
- Save objects with expiry time in Book storage.
- Retrieve objects from storage and automatically check for expiry.
- Delete objects from storage.
- Destroy the entire storage.
- Retrieve all keys of objects stored in the storage.
To use ExpiryDB in your Android project, follow these steps:
- In
settings.gradle
, add maven{ url 'https://jitpack.io' }
Groovy
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Kotlin
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven ("https://jitpack.io")
}
}
Note: If you add this in
build.gradle
(project level), it won't work. You must add it in thesettings.gradle
instead.
- Add the ExpiryDB dependency to your app-level
build.gradle
file:
Groovy
dependencies {
...
implementation 'com.github.rdnasim:ExpiryDB:1.0.2'
}
Kotlin
dependencies {
...
implementation ("com.github.rdnasim:ExpiryDB:1.0.2")
}
- Import the library package
import com.riadul.expirydb.ExpiryDB
- Initialize ExpiryDB with your application context:
ExpiryDB.init(applicationContext)
- Use the book() method to get an instance of ExpiryDBBook for performing storage operations:
val dbBook = ExpiryDB.book()
- Save an object with an expiry time:
val key = "my_object"
val value = MyObject()
val expiryTimeMillis = 60000L // Expiry time in milliseconds
dbBook.write(key, value, expiryTimeMillis)
- Retrieve an object from storage:
val retrievedValue = dbBook.read(key)
The retrieved value will be null
if the object has expired or does not exist.
- Delete an object from storage:
dbBook.delete(key)
- Retrieve all keys of objects stored in the storage:
val keys = dbBook.getAllKeys()
This project is licensed under the Apache License - see the LICENSE file for details.