Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.MpStyle:jcache:v2.1.0'
}
dependencies {
implementation("com.github.MpStyle:jcache:v2.1.0")
}
<dependency>
<groupId>com.github.MpStyle</groupId>
<artifactId>jcache</artifactId>
<version>v2.1.0</version>
</dependency>
libraryDependencies += "com.github.MpStyle" % "jcache" % "v2.1.0"
:dependencies [[com.github.MpStyle/jcache "v2.1.0"]]
Lazy and naive cache using in memory SQLite, H2 and MySQL database.
<repositories>
...
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
...
</repositories>
...
<dependency>
<groupId>com.github.MpStyle</groupId>
<artifactId>jcache</artifactId>
<version>v2.2.0</version>
</dependency>
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
...
dependencies {
compile 'com.github.MpStyle:jcache:v2.2.0'
}
Create a connection using SQLite:
Cache cache = CacheBuilder.getSqliteCache();
or using H2:
Cache cache = CacheBuilder.getH2Cache();
Insert a new item in the cache:
Cache cache = CacheBuilder.getSqliteCache();
cache.add("a", "b");
[...]
String value = cache.get("a");
Or:
Cache cache = CacheBuilder.getSqliteCache();
CacheItem item = new CacheItem();
item.setKey("a");
item.setTtl(3);
item.setValue("b");
cache.add(item);
[...]
String value = cache.get("a");
To clear the cache:
cache.clear();
To delete a specific item
cache.delete("key_of_the_item_to_delete");