{"id":8232,"date":"2013-02-07T19:00:58","date_gmt":"2013-02-07T17:00:58","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=8232"},"modified":"2014-11-08T14:17:55","modified_gmt":"2014-11-08T12:17:55","slug":"caching-with-spring-data-redis","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2013\/02\/caching-with-spring-data-redis.html","title":{"rendered":"Caching with Spring Data Redis"},"content":{"rendered":"<p>In the example below, I\u2019ll show you how to use the <a href=\"http:\/\/www.springsource.org\/spring-data\/redis\">Spring Data \u2013 Redis<\/a> project as a caching provider for the Spring Cache Abstraction that was <a href=\"http:\/\/blog.springsource.com\/2011\/02\/23\/spring-3-1-m1-caching\/\">introduced<\/a> in Spring 3.1. I get a lot of questions about how to use Spring\u2019s Java based configuration so I\u2019ll provide both XML and Java based configurations for your review.<\/p>\n<h2>Dependencies<\/h2>\n<p>The following dependencies were used in this example:<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<\/p>\n<pre class=\" brush:xml\">&lt;?xml version='1.0' encoding='UTF-8'?&gt;\r\n&lt;project xmlns='http:\/\/maven.apache.org\/POM\/4.0.0'\r\n    xsi:schemaLocation='http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/maven-v4_0_0.xsd'\r\n    xmlns:xsi='http:\/\/www.w3.org\/2001\/XMLSchema-instance'&gt;\r\n    &lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\r\n    &lt;groupId&gt;com.joshuawhite.example&lt;\/groupId&gt;\r\n    &lt;artifactId&gt;spring-redis-example&lt;\/artifactId&gt;\r\n    &lt;version&gt;1.0&lt;\/version&gt;\r\n    &lt;packaging&gt;jar&lt;\/packaging&gt;\r\n    &lt;name&gt;Spring Redis Example&lt;\/name&gt;\r\n    &lt;dependencies&gt;\r\n        &lt;dependency&gt;\r\n            &lt;groupId&gt;org.springframework.data&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;spring-data-redis&lt;\/artifactId&gt;\r\n            &lt;version&gt;1.0.2.RELEASE&lt;\/version&gt;\r\n        &lt;\/dependency&gt;        \r\n        &lt;!-- required for @Configuration annotation --&gt;\r\n        &lt;dependency&gt;\r\n            &lt;groupId&gt;cglib&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;cglib&lt;\/artifactId&gt;\r\n            &lt;version&gt;2.2.2&lt;\/version&gt;\r\n        &lt;\/dependency&gt;\r\n        &lt;dependency&gt;\r\n            &lt;groupId&gt;redis.clients&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;jedis&lt;\/artifactId&gt;\r\n            &lt;version&gt;2.0.0&lt;\/version&gt;\r\n            &lt;type&gt;jar&lt;\/type&gt;\r\n            &lt;scope&gt;compile&lt;\/scope&gt;\r\n        &lt;\/dependency&gt;\r\n        &lt;dependency&gt;\r\n            &lt;groupId&gt;log4j&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;log4j&lt;\/artifactId&gt;\r\n            &lt;version&gt;1.2.14&lt;\/version&gt;\r\n        &lt;\/dependency&gt;\r\n    &lt;\/dependencies&gt;\r\n    &lt;build&gt;\r\n        &lt;plugins&gt;\r\n            &lt;plugin&gt;\r\n                &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;\r\n                &lt;artifactId&gt;maven-compiler-plugin&lt;\/artifactId&gt;\r\n                &lt;configuration&gt;\r\n                    &lt;source&gt;1.6&lt;\/source&gt;\r\n                    &lt;target&gt;1.6&lt;\/target&gt;\r\n                &lt;\/configuration&gt;\r\n            &lt;\/plugin&gt;\r\n        &lt;\/plugins&gt;\r\n    &lt;\/build&gt;\r\n&lt;\/project&gt;<\/pre>\n<p><strong>Code and Configuration<\/strong><\/p>\n<p>The <code>HelloService<\/code> example below is very simple. As you will see in the implementation, it simply returns a String with \u201cHello\u201d prepended to the name that is passed in.<\/p>\n<pre class=\" brush:java\">package com.joshuawhite.example.service;\r\n\r\npublic interface HelloService {\r\n\r\n    String getMessage(String name);\r\n\r\n}<\/pre>\n<p>Looking at the <code>HelloServiceImpl<\/code> class (below), you can see that I am leveraging Spring\u2019s @Cacheable annotation to add caching capabilities to the <code>getMessage<\/code> method. For more details on the capabilities of this annotation, take a look at the <a href=\"http:\/\/static.springsource.org\/spring\/docs\/3.2.x\/spring-framework-reference\/html\/cache.html\">Cache Abstraction documentation<\/a>. For fun, I am using the <a href=\"http:\/\/static.springsource.org\/spring\/docs\/3.2.x\/spring-framework-reference\/html\/expressions.html\">Spring Expression Language (SpEL)<\/a> to define a condition. In this example, the methods response will only be cached when the name passed in is \u201cJoshua\u201d.<\/p>\n<pre class=\" brush:java\">package com.joshuawhite.example.service;\r\n\r\nimport org.springframework.cache.annotation.Cacheable;\r\nimport org.springframework.stereotype.Service;\r\n\r\n@Service('helloService')\r\npublic class HelloServiceImpl implements HelloService {\r\n\r\n    \/**\r\n     * Using SpEL for conditional caching - only cache method executions when\r\n     * the name is equal to 'Joshua'\r\n     *\/\r\n    @Cacheable(value='messageCache', condition=''Joshua'.equals(#name)')\r\n    public String getMessage(String name) {\r\n        System.out.println('Executing HelloServiceImpl' +\r\n                        '.getHelloMessage(\\'' + name + '\\')');\r\n\r\n        return 'Hello ' + name + '!';\r\n    }\r\n\r\n}<\/pre>\n<p>The <code>App<\/code> class below contains our <code>main<\/code> method and is used to select between XML and Java based configurations. Each of the <code>System.out.println<\/code>\u2018s are used to demonstrate when caching is taking place. As a reminder, we only expect method executions passing in \u201cJoshua\u201d to be cached. This will be more clear when we look at the programs output later.<\/p>\n<pre class=\" brush:java\">package com.joshuawhite.example;\r\n\r\nimport org.springframework.cache.Cache;\r\nimport org.springframework.cache.CacheManager;\r\nimport org.springframework.context.ApplicationContext;\r\nimport org.springframework.context.annotation.AnnotationConfigApplicationContext;\r\nimport org.springframework.context.support.GenericXmlApplicationContext;\r\n\r\nimport com.joshuawhite.example.config.AppConfig;\r\nimport com.joshuawhite.example.service.HelloService;\r\n\r\npublic class App {\r\n\r\n    public static void main(String[] args) {\r\n\r\n        boolean useJavaConfig  = true;\r\n        ApplicationContext ctx = null;\r\n\r\n        \/\/Showing examples of both Xml and Java based configuration\r\n        if (useJavaConfig ) {\r\n                ctx = new AnnotationConfigApplicationContext(AppConfig.class);\r\n        }\r\n        else {\r\n                ctx = new GenericXmlApplicationContext('\/META-INF\/spring\/app-context.xml');\r\n        }\r\n\r\n        HelloService helloService = ctx.getBean('helloService', HelloService.class);\r\n\r\n        \/\/First method execution using key='Josh', not cached\r\n        System.out.println('message: ' + helloService.getMessage('Josh'));\r\n\r\n        \/\/Second method execution using key='Josh', still not cached\r\n        System.out.println('message: ' + helloService.getMessage('Josh'));\r\n\r\n        \/\/First method execution using key='Joshua', not cached\r\n        System.out.println('message: ' + helloService.getMessage('Joshua'));\r\n\r\n        \/\/Second method execution using key='Joshua', cached\r\n        System.out.println('message: ' + helloService.getMessage('Joshua'));\r\n\r\n        System.out.println('Done.');\r\n    }\r\n\r\n}<\/pre>\n<p>Notice that component scanning is still used when using the XML based configuration. You can see that I am using the <code>@Service<\/code> annotation on line 6 of <code>HelloServiceImpl.java<\/code> above. Next we will take a look at how to configure a <code>jedisConnectionFactory<\/code>, <code>redisTemplate<\/code> and <code>cacheManager<\/code>.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h2>Configuring the JedisConnectionFactory<\/h2>\n<p>For this example, I chose to use <a href=\"https:\/\/github.com\/xetorthio\/jedis\">Jedis<\/a> as our Java client of choice because it is listed on the Redis site as being the <a href=\"http:\/\/redis.io\/clients\">\u201crecommended\u201d<\/a> client library for Java. As you can see, the setup is very straight forward. While I am explicitly setting use-pool=true, it the source code indicates that this is the default. The JedisConnectionFactory also provides the following defaults when not explicitly set:<\/p>\n<ul>\n<li>hostName=\u201dlocalhost\u201d<\/li>\n<li>port=6379<\/li>\n<li>timeout=2000 ms<\/li>\n<li>database=0<\/li>\n<li>usePool=true<\/li>\n<\/ul>\n<p><strong>Note:<\/strong> Though the database index is configurable, the<code> JedisConnectionFactory<\/code> only supports connecting to one Redis database at a time. Because Redis is single threaded, you are encouraged to set up multiple instances of Redis instead of using multiple databases within a single process. This allows you to get better CPU\/resource utilization. If you plan to use redis-cluster, only a single database is supported. For more information about the defaults used in the connection pool, take a look at the <a href=\"https:\/\/github.com\/xetorthio\/jedis\/blob\/master\/src\/main\/java\/redis\/clients\/jedis\/JedisPoolConfig.java\">implementation of <code>JedisPoolConfig<\/code><\/a> or the Apache Commons Pool<code> org.apache.commons.pool.impl.GenericObjectPool.Config<\/code> and it\u2019s enclosing<code> <\/code><a href=\"http:\/\/commons.apache.org\/pool\/api-1.6\/org\/apache\/commons\/pool\/impl\/GenericObjectPool.html\"><code>org.apache.commons.pool.impl.GenericObjectPool<\/code><\/a> class.<\/p>\n<h2>Configuring the RedisTemplate<\/h2>\n<p>As you would expect from a Spring \u201ctemplate\u201d class, the <a href=\"http:\/\/static.springsource.org\/spring-data\/data-redis\/docs\/current\/api\/index.html?org\/springframework\/data\/redis\/core\/RedisTemplate.html\"><code>RedisTemplate<\/code><\/a> takes care of serialization and connection management and (providing you are using a connection pool) is thread safe. By default, the RedisTemplate uses Java serialization (<a href=\"http:\/\/static.springsource.org\/spring-data\/data-redis\/docs\/current\/api\/index.html?org\/springframework\/data\/redis\/serializer\/JdkSerializationRedisSerializer.html\"><code>JdkSerializationRedisSerializer<\/code><\/a>). Note that serializing data into Redis essentially makes Redis an \u201copaque\u201d cache. While other serializers allow you to map the data into Redis, I have found serialization, especially when dealing with object graphs, is faster and simpler to use. That being said, if you have a requirement that other non-java applications be able to access this data, mapping is your best out-of-the-box option. I have had a great experience using <a href=\"http:\/\/www.caucho.com\/resin-3.0\/protocols\/hessian.xtp\">Hessian<\/a> and <a href=\"http:\/\/code.google.com\/p\/protobuf\/\">Google Protocol Buffers<\/a>\/<a href=\"http:\/\/code.google.com\/p\/protostuff\/\">protostuff<\/a>. I\u2019ll share some sample implementations of the <code>RedisSerializer<\/code> in a future post.<\/p>\n<h2>Configuring the RedisCacheManager<\/h2>\n<p>Configuring the <code>RedisCacheManager<\/code> is straight forward. As a reminder, the <code>RedisCacheManager<\/code> is dependent on a <code>RedisTemplate<\/code> which is dependent on a connection factory, in our case <code>JedisConnectionFactory<\/code>, that can only connect to a single database at a time. As a workaround, the RedisCacheManager has the capability of setting up a prefix for your cache keys.<\/p>\n<p><strong>Warning:<\/strong> When dealing with other caching solutions, Spring\u2019s CacheManger usually contains a map of <code>Cache<\/code> (each implementing map like functionality) implementations that are backed by separate caches. Using the default <code>RedisCacheManager<\/code> configuration, this is not the case. Based on the javadoc comment on the <code>RedisCacheManager<\/code>, its not clear if this is a bug or simply incomplete documentation.<\/p>\n<p>\u201c\u2026By default saves the keys by appending a prefix (which acts as a namespace).\u201d<\/p>\n<p>While the DefaultRedisCachePrefix which is configured in the <code>RedisCacheManager<\/code> certainly supports this, it is not enabled by default. As a result, when you ask the <code>RedisCacheManager<\/code> for a <code>Cache<\/code> of a given name, it simply creates a new <code>Cache<\/code> instance that points to the same database. As a result, the <code>Cache<\/code> instances are all the same. The same key will retrieve the same value in all <code>Cache<\/code> instances.<\/p>\n<p>As the javadoc comment alludes to, prefixs can be used to setup client managed (Redis doesn\u2019t support this functionality natively) namespaces that essentially create \u201cvirtual\u201d caches within the same database. You can turn this feature on by calling <code>redisCacheManager.setUsePrefix(true)<\/code> either using the Spring XML or Java configuration.<\/p>\n<pre class=\" brush:xml\">&lt;?xml version='1.0' encoding='UTF-8'?&gt;\r\n&lt;beans\r\n    xmlns='http:\/\/www.springframework.org\/schema\/beans'\r\n    xmlns:xsi='http:\/\/www.w3.org\/2001\/XMLSchema-instance'\r\n    xmlns:context='http:\/\/www.springframework.org\/schema\/context'\r\n    xmlns:c='http:\/\/www.springframework.org\/schema\/c'\r\n    xmlns:p='http:\/\/www.springframework.org\/schema\/p'\r\n    xmlns:cache='http:\/\/www.springframework.org\/schema\/cache'\r\n    xsi:schemaLocation='\r\n\r\nhttp:\/\/www.springframework.org\/schema\/beansvhttp:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\r\n\r\n        http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context.xsd\r\n        http:\/\/www.springframework.org\/schema\/cache http:\/\/www.springframework.org\/schema\/cache\/spring-cache.xsd'&gt;\r\n\r\n    &lt;context:component-scan base-package='com.joshuawhite.example.service' \/&gt;\r\n    &lt;context:property-placeholder location='classpath:\/redis.properties'\/&gt;\r\n\r\n    &lt;!-- turn on declarative caching --&gt;\r\n    &lt;cache:annotation-driven \/&gt;\r\n\r\n    &lt;!-- Jedis ConnectionFactory --&gt;\r\n    &lt;bean\r\n        id='jedisConnectionFactory'\r\n        class='org.springframework.data.redis.connection.jedis.JedisConnectionFactory'\r\n        p:host-name='${redis.host-name}'\r\n        p:port='${redis.port}'\r\n        p:use-pool='true'\/&gt;\r\n\r\n    &lt;!-- redis template definition --&gt;\r\n    &lt;bean\r\n        id='redisTemplate'\r\n        class='org.springframework.data.redis.core.RedisTemplate'\r\n        p:connection-factory-ref='jedisConnectionFactory'\/&gt;\r\n\r\n    &lt;!-- declare Redis Cache Manager --&gt;\r\n    &lt;bean\r\n        id='cacheManager'\r\n        class='org.springframework.data.redis.cache.RedisCacheManager'\r\n        c:template-ref='redisTemplate'\/&gt;\r\n\r\n&lt;\/beans&gt;<\/pre>\n<p>The Java configuration below is equivalent to the XML configuration above. People usually get hung up on using a <code>PropertySourcesPlaceholderConfigurer<\/code>. To do that, you need to use <em>both<\/em> the <code>@PropertySource<\/code> annotation and define a <code>PropertySourcesPlaceholderConfigurer<\/code> bean. The <code>PropertySourcesPlaceholderConfigurer<\/code> will not be sufficient on its own.<\/p>\n<pre class=\" brush:java\">package com.joshuawhite.example.config;\r\n\r\nimport org.springframework.beans.factory.annotation.Value;\r\nimport org.springframework.cache.CacheManager;\r\nimport org.springframework.context.annotation.Bean;\r\nimport org.springframework.context.annotation.ComponentScan;\r\nimport org.springframework.context.annotation.Configuration;\r\nimport org.springframework.context.annotation.PropertySource;\r\nimport org.springframework.context.support.PropertySourcesPlaceholderConfigurer;\r\nimport org.springframework.data.redis.cache.RedisCacheManager;\r\nimport org.springframework.data.redis.connection.jedis.JedisConnectionFactory;\r\nimport org.springframework.data.redis.core.RedisTemplate;\r\n\r\n@Configuration\r\n@ComponentScan('com.joshuawhite.example')\r\n@PropertySource('classpath:\/redis.properties')\r\npublic class AppConfig {\r\n\r\n private @Value('${redis.host-name}') String redisHostName;\r\n private @Value('${redis.port}') int redisPort;\r\n\r\n @Bean\r\n public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {\r\n     return new PropertySourcesPlaceholderConfigurer();\r\n }\r\n\r\n @Bean\r\n JedisConnectionFactory jedisConnectionFactory() {\r\n     JedisConnectionFactory factory = new JedisConnectionFactory();\r\n     factory.setHostName(redisHostName);\r\n     factory.setPort(redisPort);\r\n     factory.setUsePool(true);\r\n     return factory;\r\n }\r\n\r\n @Bean\r\n RedisTemplate&lt;Object, Object&gt; redisTemplate() {\r\n     RedisTemplate&lt;Object, Object&gt; redisTemplate = new RedisTemplate&lt;Object, Object&gt;();\r\n     redisTemplate.setConnectionFactory(jedisConnectionFactory());\r\n     return redisTemplate;\r\n }\r\n\r\n @Bean\r\n CacheManager cacheManager() {\r\n     return new RedisCacheManager(redisTemplate());\r\n }\r\n\r\n}<\/pre>\n<p>Here is the properties file that is used by both configurations. Replace the values below with the host and port that you are using.<\/p>\n<pre class=\" brush:java\">redis.host-name=yourHostNameHere\r\nredis.port=6379<\/pre>\n<h2>Output<\/h2>\n<p>Finally, here is the output from our brief example application. Notice that no matter how many times we call <code>getHelloMessage('Josh')<\/code>, the methods response does not get cached. This is because we defined a condition (see <code>HelloServiceImpl.java<\/code>, line 13) where we only cache the methods response when the name equals \u201cJoshua\u201d. When we call <code>getHelloMessage('Joshua')<\/code> for the first time, the method is executed. The second time however, it is not.<\/p>\n<pre class=\" brush:bash\">Executing HelloServiceImpl.getHelloMessage('Josh')\r\nmessage: Hello Josh!\r\nExecuting HelloServiceImpl.getHelloMessage('Josh')\r\nmessage: Hello Josh!\r\nExecuting HelloServiceImpl.getHelloMessage('Joshua')\r\nmessage: Hello Joshua!\r\nExecuting HelloServiceImpl.getHelloMessage('Joshua')\r\nmessage: Hello Joshua!\r\nDone.<\/pre>\n<p>This concludes our brief over view of caching with Spring Data Redis.<br \/>\n&nbsp;<\/p>\n<p><strong><em>Reference: <\/em><\/strong><a href=\"http:\/\/blog.joshuawhite.com\/java\/caching-with-spring-data-redis\/\">Caching with Spring Data Redis<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a> Joshua White at the <a href=\"http:\/\/blog.joshuawhite.com\/\">Joshua White&#8217;s Blog<\/a> blog.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the example below, I\u2019ll show you how to use the Spring Data \u2013 Redis project as a caching provider for the Spring Cache Abstraction that was introduced in Spring 3.1. I get a lot of questions about how to use Spring\u2019s Java based configuration so I\u2019ll provide both XML and Java based configurations for &hellip;<\/p>\n","protected":false},"author":350,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[113,117,30,321],"class_list":["post-8232","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-nosql","tag-redis","tag-spring","tag-spring-data"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Caching with Spring Data Redis<\/title>\n<meta name=\"description\" content=\"In the example below, I\u2019ll show you how to use the Spring Data \u2013 Redis project as a caching provider for the Spring Cache Abstraction that was introduced\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2013\/02\/caching-with-spring-data-redis.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Caching with Spring Data Redis\" \/>\n<meta property=\"og:description\" content=\"In the example below, I\u2019ll show you how to use the Spring Data \u2013 Redis project as a caching provider for the Spring Cache Abstraction that was introduced\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2013\/02\/caching-with-spring-data-redis.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2013-02-07T17:00:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-11-08T12:17:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Joshua White\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Joshua White\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/02\\\/caching-with-spring-data-redis.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/02\\\/caching-with-spring-data-redis.html\"},\"author\":{\"name\":\"Joshua White\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/9f38610fe898a0c40ac6f3c40178d4cd\"},\"headline\":\"Caching with Spring Data Redis\",\"datePublished\":\"2013-02-07T17:00:58+00:00\",\"dateModified\":\"2014-11-08T12:17:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/02\\\/caching-with-spring-data-redis.html\"},\"wordCount\":963,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/02\\\/caching-with-spring-data-redis.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"NoSQL\",\"Redis\",\"Spring\",\"Spring Data\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/02\\\/caching-with-spring-data-redis.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/02\\\/caching-with-spring-data-redis.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/02\\\/caching-with-spring-data-redis.html\",\"name\":\"Caching with Spring Data Redis\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/02\\\/caching-with-spring-data-redis.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/02\\\/caching-with-spring-data-redis.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2013-02-07T17:00:58+00:00\",\"dateModified\":\"2014-11-08T12:17:55+00:00\",\"description\":\"In the example below, I\u2019ll show you how to use the Spring Data \u2013 Redis project as a caching provider for the Spring Cache Abstraction that was introduced\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/02\\\/caching-with-spring-data-redis.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/02\\\/caching-with-spring-data-redis.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/02\\\/caching-with-spring-data-redis.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/02\\\/caching-with-spring-data-redis.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Caching with Spring Data Redis\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/9f38610fe898a0c40ac6f3c40178d4cd\",\"name\":\"Joshua White\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d2e10510aa15fa7483f8bb8739b3a9d38ab12664c9c86fa254bc6ccf74bd6e81?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d2e10510aa15fa7483f8bb8739b3a9d38ab12664c9c86fa254bc6ccf74bd6e81?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d2e10510aa15fa7483f8bb8739b3a9d38ab12664c9c86fa254bc6ccf74bd6e81?s=96&d=mm&r=g\",\"caption\":\"Joshua White\"},\"description\":\"Joshua White has more than twelve years of experience developing and architecting complex software systems for a number of financial and health services organizations. Joshua is also co-author of the book Spring in Practice (Manning).\",\"sameAs\":[\"http:\\\/\\\/blog.joshuawhite.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/joshua-white\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Caching with Spring Data Redis","description":"In the example below, I\u2019ll show you how to use the Spring Data \u2013 Redis project as a caching provider for the Spring Cache Abstraction that was introduced","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2013\/02\/caching-with-spring-data-redis.html","og_locale":"en_US","og_type":"article","og_title":"Caching with Spring Data Redis","og_description":"In the example below, I\u2019ll show you how to use the Spring Data \u2013 Redis project as a caching provider for the Spring Cache Abstraction that was introduced","og_url":"https:\/\/www.javacodegeeks.com\/2013\/02\/caching-with-spring-data-redis.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-02-07T17:00:58+00:00","article_modified_time":"2014-11-08T12:17:55+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Joshua White","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Joshua White","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2013\/02\/caching-with-spring-data-redis.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/02\/caching-with-spring-data-redis.html"},"author":{"name":"Joshua White","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/9f38610fe898a0c40ac6f3c40178d4cd"},"headline":"Caching with Spring Data Redis","datePublished":"2013-02-07T17:00:58+00:00","dateModified":"2014-11-08T12:17:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/02\/caching-with-spring-data-redis.html"},"wordCount":963,"commentCount":3,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/02\/caching-with-spring-data-redis.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["NoSQL","Redis","Spring","Spring Data"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2013\/02\/caching-with-spring-data-redis.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2013\/02\/caching-with-spring-data-redis.html","url":"https:\/\/www.javacodegeeks.com\/2013\/02\/caching-with-spring-data-redis.html","name":"Caching with Spring Data Redis","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/02\/caching-with-spring-data-redis.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/02\/caching-with-spring-data-redis.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2013-02-07T17:00:58+00:00","dateModified":"2014-11-08T12:17:55+00:00","description":"In the example below, I\u2019ll show you how to use the Spring Data \u2013 Redis project as a caching provider for the Spring Cache Abstraction that was introduced","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/02\/caching-with-spring-data-redis.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2013\/02\/caching-with-spring-data-redis.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2013\/02\/caching-with-spring-data-redis.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2013\/02\/caching-with-spring-data-redis.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Caching with Spring Data Redis"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/9f38610fe898a0c40ac6f3c40178d4cd","name":"Joshua White","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d2e10510aa15fa7483f8bb8739b3a9d38ab12664c9c86fa254bc6ccf74bd6e81?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d2e10510aa15fa7483f8bb8739b3a9d38ab12664c9c86fa254bc6ccf74bd6e81?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d2e10510aa15fa7483f8bb8739b3a9d38ab12664c9c86fa254bc6ccf74bd6e81?s=96&d=mm&r=g","caption":"Joshua White"},"description":"Joshua White has more than twelve years of experience developing and architecting complex software systems for a number of financial and health services organizations. Joshua is also co-author of the book Spring in Practice (Manning).","sameAs":["http:\/\/blog.joshuawhite.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/joshua-white"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/8232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/350"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=8232"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/8232\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=8232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=8232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=8232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}