Skip to content

rdnasim/expirydb

Repository files navigation

Logo of ExpiryDB

ExpiryDB

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.

Features

  • 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.

Installation

To use ExpiryDB in your Android project, follow these steps:

  1. 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 the settings.gradle instead.

  1. 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")
}

Usage

  1. Import the library package
import com.riadul.expirydb.ExpiryDB
  1. Initialize ExpiryDB with your application context:
ExpiryDB.init(applicationContext)
  1. Use the book() method to get an instance of ExpiryDBBook for performing storage operations:
val dbBook = ExpiryDB.book()
  1. 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)
  1. 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.

  1. Delete an object from storage:
dbBook.delete(key)
  1. Retrieve all keys of objects stored in the storage:
val keys = dbBook.getAllKeys()

License

This project is licensed under the Apache License - see the LICENSE file for details.

About

ExpiryDB is a lightweight Android library that provides storage operations with expiry time for objects.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages