Memcached with Spring - java

I have a Spring based application that uses Spring core, Spring MVC and Spring Data (Mongo) on the server side, and designed as a typical 3-tier application.
I have a list of services, that are typical Spring services/beans that I wish you integrate with memcached to cache some of my service results.
Can someone guide me to the steps to integrate memcached with spring for such an application?
A sample/tutorial/blog that gives a step by step process would be just great.
Thanks.

If you use Spring 3.1 take a look at Spring Cache abstraction. It's the easiest way to integrate caching in Spring application. Unfortunately Spring doesn't support memcached out of the box, there's only support for ehcache.
As far as I know there isn't available any provider that can store data to memcached through Spring Cache. In few days next version 3.0.0 of Simple Spring Memcached is going to be released with such support. In mean time you may try one of the latest snapshot or use Simple Spring Memcached 2.0.0 directly without Spring Cache abstraction.
UPDATE: Simple Spring Memcached 3.0.0 with Spring Cache integration is already available.

It's very trivial to do. You can look at 3levelmemcache project as an example at github its Spring based abstraction.

Related

Ehcache in Spring boot microservices

Ehcache works fine in my spring boot app without any problem, but when I run two/more instance of same microservice, data is inconsistent (each spring boot app is having one cache store) how can i implement distributed cache only by using ehcache is it possible ?. Downvoters comments please.
Note : I dont want to use redis database

Is spring-data-redis compatible with Spring 3?

I have been looking all over the internet on how to configure Spring MVC 3 with redis but all in vain. I want to connect to redis using Spring MVC 3.
I have worked with spring boot and spring-data-redis and everything is working fine. I can connect to redis and store sessions. But the project I am currently working on is legacy based. It uses spring 3 but I believe spring-data-redis is compatible with spring 4 and above. Are there any alternates to make connection between spring 3 and redis. Any tutorial would be helpful.
I expect to store session data like username in the redis using Spring MVC 3
Well, from the documentation of the oldiest available spring-data-redis release
it looks like the minimal 2.x version is indeed spring 4
However, Spring data redis 1.x should work with spring 3.x:
https://docs.spring.io/spring-data/redis/docs/1.4.0.M1/reference/htmlsingle/#why-spring-redis
Having said that I haven't tried it by myself and if you're only storing sessions in redis, maybe using spring data is an overkill.
After all you can create a Jedis plugin by yourself, expose it as a bean and call the commands directly via the jedis driver. Its also possible to go with reactive client...

Dropwizard spring data couchbase

I am building a project with Dropwizard, Couchbase and ElasticSearch.
I am looking for a persistence layer like an ODM for Dropwizard and CouchBase. I looked over and found Spring-data-couchbase. Can I integrate DropWizard with Spring-data-couchbase and just use Spring-data-couchbase just for persistence? If I just use Spring-data-couchbase will it create an IOC container?
if you are looking for an ODM layer, we recently added a light one to the Java SDK, see Entity Mapping: http://blog.couchbase.com/javasdk-2.2-dp
Also if you are looking to use Spring Data Couchbase, you should maybe look into Spring boot, that basically does the same things as DropWizard. But of course Spring Data Couchbase is more integrated with Spring Boot than DropWizard.
As for DropWizard and Spring, yes I guess you would drag some Spring dependency in there so it might create some stuff that already have an equivalent in Dropwizard. But I have no knowledge of Dropwizard so, not sure.

Using spring core functionalities in tomcat based jersey application

I want to use spring's dependency injection for now(other core functionalites later maybe) in tomcat application.
I want to set up spring 2.5.5 in tomcat7, But don't have clarity on how to do this.
Specifically I am confused because I don't know whether to use Spring MVC or use just spring in tomcat.
I found this question helpful: Tomcat with Spring, But still didn't get the whole scenario on how to setup tomcat with spring.
You can do either, using just core spring with tomcat is fine. MVC provides additional functionality.
Take a look at the spring source examples on github, and read their docs.
(BTW I thouroughy spring-MVC component - it really saves time developing webapps)

spring 3.1 #Cacheable example

I am new to spring annotation and i want to create a sample example which shows the use of #Cacheable annotation in spring 3.1 does any one have guidance to create this ?
Hope following link may be helpful to you... A sample application.
Also have a look on Spring's documentation for cache abstraction and spring source blog post.
There are lots of links to learn from
simple-spring-memcached
Cache Abstraction Spring 3.2
Spring Expression Language (SpEL) Spring 3.2
Cache abstraction in Spring 3/
I did a POC using spring cache, Simple Spring Memcached and Memcache. The svn link of working application code is here
Simple Spring Memcached – Spring Caching Abstraction and Memcached

Categories

Resources