Giter VIP home page Giter VIP logo

spring_memcached's Introduction

Memcached with Spring Boot MIT license Build 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.
@Bean
	public MemcachedClient cacheClient() {
		InetSocketAddress ia = new InetSocketAddress("localhost", 11211);
		MemcachedClient cacheClient = null;
		try {
		 cacheClient = new MemcachedClient(ia);
		} catch (IOException e) {
			e.printStackTrace();
		}
		LOGGER.info("Cache setup done.");
		return cacheClient;
	}

Done !!!!

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

Add something to cache

@Autowired
private MemcachedClient memcachedClient;

memcachedClient.add(key, 0, value);

Fetch from cache

String value = (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

Stack Detail
Java Java 8
Spring boot 2.0.3.RELEASE
Database MySql

spring_memcached's People

Contributors

codestuff-repo avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

sujitmajumdar42

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.