The library provides Java binding for memcache, allowing seamless integration of memcache's in-memory caching capabilities into Java applications. It simplifies the process of interacting with memcache's caching functionalities from Java code, leveraging the power and efficiency of memcache within a Java environment.
Additionally, the library inherently supports bulk read/write operations to the cache, iteration capabilities, cache configuration management etc.
You can find this library in Maven central repository.
Include the latest version of memcache-client into your project:
In Maven:
<dependency>
<groupId>io.github.s-bose7</groupId>
<artifactId>memcache-client</artifactId>
<version>version</version>
</dependency>Cache initialization follows the builder and simple factory patterns. Clients have the option to initialize the cache with no configuration, in which case the factory will provide a default cache configuration.
package com.memcache.demo;
import io.github.sbose7.Cache;
import io.github.sbose7.config.CacheConfiguration;
import io.github.sbose7.config.ConfigurationBuilder;
import io.github.sbose7.manager.CacheManager;
import io.github.sbose7.exception.CacheInitializationException;
public class Main {
public static void main(String[] args) {
CacheConfiguration config = new ConfigurationBuilder()
.setInitialSize(100)
.setCacheName("db-cache-id-5432")
.setExpirationTime(60)
.setLoggingEnabled(false)
.setCompressionEnabled(false)
.build();
try {
Cache memCache = CacheManager.createCache(config);
} catch (CacheInitializationException e){
e.printStackTrace();
}
memCache.put(13, 26);
System.out.println(memCache.get(13)); // 26
System.out.println(memCache.remove(13)); // true
System.out.println(memCache.containsKey(13)); // false
}
}