Skip to content

Repository files navigation

Memcached with Spring Boot MIT licenseBuild Status

Why Memcached ?

Are you interacting with Database for each transaction?

Then you must apply a cache mechanism to avoid multiple database calls and faster response.

A free, opensource, in-memory caching system to speedup application by reducing database load.

Memcached with Spring

In this project you will find basic usage of memcached in spring REST application.

How to use?

Add dependency

// For Gradle project add following dependency.

compile("net.spy:spymemcached:2.12.3")

Setup Memcached

Add MemcachedClient bean in your springboot config file.

// Connecting to memcached// [host = localhost ,PORT = 11211]// Initializing MemcachedClient.@BeanpublicMemcachedClientcacheClient() {
InetSocketAddressia = newInetSocketAddress("localhost", 11211);
MemcachedClientcacheClient = null;
try {
cacheClient = newMemcachedClient(ia);
} catch (IOExceptione) {
e.printStackTrace();
}
LOGGER.info("Cache setup done.");
returncacheClient;
}

Done !!!!

Now you are ready to use memcache hosted on your local machine.
Its simple, right?

Add something to cache

@AutowiredprivateMemcachedClientmemcachedClient;
memcachedClient.add(key, 0, value);

Fetch from cache

Stringvalue = (String) memcachedClient.get(key);

Delete from cache

memcachedClient.delete(key);

Flush everything

memcachedClient.flush();

Want more?

Memcached provides lot more features for caching.
Still confused ? then,

Fork it and explore !!!!

Technology Stacks

StackDetail
JavaJava 8
Spring boot2.0.3.RELEASE
DatabaseMySql

About

Use of Memcached integrated with Spring.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages