<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Joshua White&#039;s Blog</title>
	<atom:link href="http://blog.joshuawhite.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.joshuawhite.com</link>
	<description>Technology Thoughts &#38; Musings</description>
	<lastBuildDate>Wed, 08 May 2013 19:34:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.4.5</generator>
	<item>
		<title>Deal of the Day May 8: Half off Spring in Practice!</title>
		<link>http://blog.joshuawhite.com/java/deal-of-the-day-may-8-half-off-my-book-spring-in-practice/</link>
		<pubDate>Wed, 08 May 2013 10:00:13 +0000</pubDate>
		<dc:creator><![CDATA[Joshua White]]></dc:creator>
				<category><![CDATA[JAVA]]></category>

		<guid isPermaLink="false">http://blog.joshuawhite.com/?p=108</guid>
		<description><![CDATA[<p>It has been a long road for Willie Wheeler, myself and the rest of the Manning team. Spring in Practice is finally in print. To celebrate, Manning is offering half off Spring in Practice. Enter dotd0508au in the Promotional Code box when you check out at manning.com.</p>
<p>The post <a rel="nofollow" href="http://blog.joshuawhite.com/java/deal-of-the-day-may-8-half-off-my-book-spring-in-practice/">Deal of the Day May 8: Half off Spring in Practice!</a> appeared first on <a rel="nofollow" href="http://blog.joshuawhite.com">Joshua White&#039;s Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>It has been a long road for <a href="http://springinpractice.com" title="Willie Wheeler" target="_blank">Willie Wheeler</a>, myself and the rest of the Manning team.  <a href="http://manning.com/wheeler/" title="Spring in Practice" target="_blank">Spring in Practice</a> is finally in print.  To celebrate, Manning is offering half off Spring in Practice.  Enter <strong>dotd0508au </strong>  in the Promotional Code box when you check out at manning.com. </p>
<p>The post <a rel="nofollow" href="http://blog.joshuawhite.com/java/deal-of-the-day-may-8-half-off-my-book-spring-in-practice/">Deal of the Day May 8: Half off Spring in Practice!</a> appeared first on <a rel="nofollow" href="http://blog.joshuawhite.com">Joshua White&#039;s Blog</a>.</p>
]]></content:encoded>
			</item>
		<item>
		<title>Building Redis for use on Cygwin</title>
		<link>http://blog.joshuawhite.com/open-source/building-redis-for-use-on-cygwin/</link>
		<pubDate>Sat, 02 Feb 2013 23:56:54 +0000</pubDate>
		<dc:creator><![CDATA[Joshua White]]></dc:creator>
				<category><![CDATA[OPEN SOURCE]]></category>
		<category><![CDATA[Redis]]></category>

		<guid isPermaLink="false">http://blog.joshuawhite.com/?p=92</guid>
		<description><![CDATA[<p>This is the second time I have installed Redis for use on Cygwin in the last several months. It seems that each time the version numbers change, I step in a different hole. For those of you using Cygwin (DLL version 1.7.17-1) and Redis version 2.6.9, I hope to share my experience with you so [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://blog.joshuawhite.com/open-source/building-redis-for-use-on-cygwin/">Building Redis for use on Cygwin</a> appeared first on <a rel="nofollow" href="http://blog.joshuawhite.com">Joshua White&#039;s Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>This is the second time I have installed Redis for use on Cygwin in the last several months.  It seems that each time the version numbers change, I step in a different hole.  For those of you using Cygwin (DLL version 1.7.17-1) and Redis version 2.6.9, I hope to share my experience with you so that you can save some time.</p>
<p>First, make sure that you have the &#8220;make&#8221; and &#8220;gcc&#8221; Cygwin packages installed.  Then, open up a Cygwin terminal window and then download and extract Redis using the following commands:</p>
<pre class="brush: bash; title: ; notranslate">
$ wget http://redis.googlecode.com/files/redis-2.6.9.tar.gz
$ tar xzf redis-2.6.9.tar.gz
$ cd redis-2.6.9
$ cd src
</pre>
<p>Then, within the <code>src</code> directory, add the following to the <code>redis.h</code> file:</p>
<pre class="brush: plain; title: ; notranslate">
#ifdef __CYGWIN__
#ifndef SA_ONSTACK
#define SA_ONSTACK 0x08000000
#endif
#endif
 
#if defined(__CYGWIN__)
#define strtold(a,b)    ((long double)strtod((a),(b)))
#endif
</pre>
<p>I added the code above right before the &#8220;Data types&#8221; comment (Before line 312).  The first five lines resolve the <code>`SA_ONSTACK' undeclared</code> error originally identified <a href="https://github.com/antirez/redis/issues/232">here</a>.  If you were to run make with this solution only, you would bump into the next error: <code>undefined reference to `_strtold'</code>.  The last three lines address this error.</p>
<p>Ignoring warnings, make will generate the following executables in the src directory:</p>
<ul>
<li>redis-benchmark.exe</li>
<li>redis-check-aof.exe</li>
<li>redis-check-dump.exe</li>
<li>redis-cli.exe</li>
<li>redis-sentinel.exe</li>
<li>redis-server.exe</li>
</ul>
<p>Copy these files into Cygwin&#8217;s bin directory.  To quickly test that Redis works, type in <code>redis-server</code> to start Redis with default options.  In another Cygwin terminal window, start the Redis command line interface by typing <code>redis-cli</code>.  At the prompt, simply type &#8220;<code>ping</code>&#8220;.  If Redis is up and running, it should simply reply with &#8220;<code>PONG</code>&#8220;.</p>
<p>Enjoy!</p>
<p>The post <a rel="nofollow" href="http://blog.joshuawhite.com/open-source/building-redis-for-use-on-cygwin/">Building Redis for use on Cygwin</a> appeared first on <a rel="nofollow" href="http://blog.joshuawhite.com">Joshua White&#039;s Blog</a>.</p>
]]></content:encoded>
			</item>
		<item>
		<title>Caching with Spring Data Redis</title>
		<link>http://blog.joshuawhite.com/java/caching-with-spring-data-redis/</link>
		<pubDate>Sat, 26 Jan 2013 01:17:31 +0000</pubDate>
		<dc:creator><![CDATA[Joshua White]]></dc:creator>
				<category><![CDATA[JAVA]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[Redis]]></category>
		<category><![CDATA[Spring Data]]></category>

		<guid isPermaLink="false">http://blog.joshuawhite.com/?p=35</guid>
		<description><![CDATA[<p>In the example below, I&#8217;ll show you how to use the Spring Data &#8211; 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&#8217;s Java based configuration so I&#8217;ll provide both XML and Java based configurations for [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://blog.joshuawhite.com/java/caching-with-spring-data-redis/">Caching with Spring Data Redis</a> appeared first on <a rel="nofollow" href="http://blog.joshuawhite.com">Joshua White&#039;s Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>In the example below, I&#8217;ll show you how to use the <a href="http://www.springsource.org/spring-data/redis">Spring Data &#8211; 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&#8217;s Java based configuration so I&#8217;ll provide both XML and Java based configurations for your review.</p>
<h3>Dependencies</h3>
<p>The following dependencies were used in this example:</p>
<pre class="brush: xml; title: pom.xml; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
    xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;
    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;com.joshuawhite.example&lt;/groupId&gt;
    &lt;artifactId&gt;spring-redis-example&lt;/artifactId&gt;
    &lt;version&gt;1.0&lt;/version&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;
    &lt;name&gt;Spring Redis Example&lt;/name&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
            &lt;artifactId&gt;spring-data-redis&lt;/artifactId&gt;
            &lt;version&gt;1.0.2.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;        
        &lt;!-- required for @Configuration annotation --&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;cglib&lt;/groupId&gt;
            &lt;artifactId&gt;cglib&lt;/artifactId&gt;
            &lt;version&gt;2.2.2&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;redis.clients&lt;/groupId&gt;
            &lt;artifactId&gt;jedis&lt;/artifactId&gt;
            &lt;version&gt;2.0.0&lt;/version&gt;
            &lt;type&gt;jar&lt;/type&gt;
            &lt;scope&gt;compile&lt;/scope&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;log4j&lt;/groupId&gt;
            &lt;artifactId&gt;log4j&lt;/artifactId&gt;
            &lt;version&gt;1.2.14&lt;/version&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
    &lt;build&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                &lt;configuration&gt;
                    &lt;source&gt;1.6&lt;/source&gt;
                    &lt;target&gt;1.6&lt;/target&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/build&gt;
&lt;/project&gt;
</pre>
<h3>Code and Configuration</h3>
<p>The <code>HelloService</code> example below is very simple. As you will see in the implementation, it simply returns a String with &#8220;Hello&#8221; prepended to the name that is passed in.</p>
<pre class="brush: java; title: HelloService.java; notranslate">
package com.joshuawhite.example.service;

public interface HelloService {

    String getMessage(String name);

}
</pre>
<p>Looking at the <code>HelloServiceImpl</code> class (below), you can see that I am leveraging Spring&#8217;s @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 &#8220;Joshua&#8221;.</p>
<pre class="brush: java; title: HelloServiceImpl.java; notranslate">
package com.joshuawhite.example.service;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service(&quot;helloService&quot;)
public class HelloServiceImpl implements HelloService {

    /**
     * Using SpEL for conditional caching - only cache method executions when
     * the name is equal to &quot;Joshua&quot;
     */
    @Cacheable(value=&quot;messageCache&quot;, condition=&quot;'Joshua'.equals(#name)&quot;)
    public String getMessage(String name) {
        System.out.println(&quot;Executing HelloServiceImpl&quot; +
                        &quot;.getHelloMessage(\&quot;&quot; + name + &quot;\&quot;)&quot;);

        return &quot;Hello &quot; + name + &quot;!&quot;;
    }

}
</pre>
<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>&#8216;s are used to demonstrate when caching is taking place.  As a reminder, we only expect method executions passing in &#8220;Joshua&#8221; to be cached.  This will be more clear when we look at the programs output later.</p>
<pre class="brush: java; title: App.java; notranslate">
package com.joshuawhite.example;

import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;

import com.joshuawhite.example.config.AppConfig;
import com.joshuawhite.example.service.HelloService;

public class App {

    public static void main(String[] args) {

        boolean useJavaConfig  = true;
        ApplicationContext ctx = null;

        //Showing examples of both Xml and Java based configuration
        if (useJavaConfig ) {
                ctx = new AnnotationConfigApplicationContext(AppConfig.class);
        }
        else {
                ctx = new GenericXmlApplicationContext(&quot;/META-INF/spring/app-context.xml&quot;);
        }

        HelloService helloService = ctx.getBean(&quot;helloService&quot;, HelloService.class);

        //First method execution using key=&quot;Josh&quot;, not cached
        System.out.println(&quot;message: &quot; + helloService.getMessage(&quot;Josh&quot;));

        //Second method execution using key=&quot;Josh&quot;, still not cached
        System.out.println(&quot;message: &quot; + helloService.getMessage(&quot;Josh&quot;));

        //First method execution using key=&quot;Joshua&quot;, not cached
        System.out.println(&quot;message: &quot; + helloService.getMessage(&quot;Joshua&quot;));

        //Second method execution using key=&quot;Joshua&quot;, cached
        System.out.println(&quot;message: &quot; + helloService.getMessage(&quot;Joshua&quot;));

        System.out.println(&quot;Done.&quot;);
    }

}
</pre>
<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.</p>
<p>Next we will take a look at how to configure a <code>jedisConnectionFactory</code>, <code>redisTemplate</code> and <code>cacheManager</code>.</p>
<h4>Configuring the JedisConnectionFactory</h4>
<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">&#8220;recommended&#8221;</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>
<ul>
<li>hostName=&#8221;localhost&#8221;</li>
<li>port=6379</li>
<li>timeout=2000 ms</li>
<li>database=0</li>
<li>usePool=true</li>
</ul>
<div class="woo-sc-box  info   "><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.</div>
<p>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&#8217;s enclosing <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>
<h4>Configuring the RedisTemplate</h4>
<p>As you would expect from a Spring &#8220;template&#8221; 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.</p>
<p>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 &#8220;opaque&#8221; 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.</p>
<p>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&#8217;ll share some sample implementations of the <code>RedisSerializer</code> in a future post.</p>
<h4>Configuring the RedisCacheManager</h4>
<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.</p>
<p>As a workaround, the RedisCacheManager has the capability of setting up a prefix for your cache keys.<br />
<div class="woo-sc-box  alert   "><strong>Warning:</strong> When dealing with other caching solutions, Spring&#8217;s 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>
<p>&#8220;&#8230;By default saves the keys by appending a prefix (which acts as a namespace).&#8221;</p>
<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>
<p>As the javadoc comment alludes to, prefixs can be used to setup client managed (Redis doesn&#8217;t support this functionality natively) namespaces that essentially create &#8220;virtual&#8221; 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.<br />
</div></p>
<pre class="brush: xml; title: app-context.xml; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans
    xmlns=&quot;http://www.springframework.org/schema/beans&quot;
    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
    xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
    xmlns:c=&quot;http://www.springframework.org/schema/c&quot;
    xmlns:p=&quot;http://www.springframework.org/schema/p&quot;
    xmlns:cache=&quot;http://www.springframework.org/schema/cache&quot;
    xsi:schemaLocation=&quot;
        http://www.springframework.org/schema/beansvhttp://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd&quot;&gt;

    &lt;context:component-scan base-package=&quot;com.joshuawhite.example.service&quot; /&gt;
    &lt;context:property-placeholder location=&quot;classpath:/redis.properties&quot;/&gt;

    &lt;!-- turn on declarative caching --&gt;
    &lt;cache:annotation-driven /&gt;

    &lt;!-- Jedis ConnectionFactory --&gt;
    &lt;bean
        id=&quot;jedisConnectionFactory&quot;
        class=&quot;org.springframework.data.redis.connection.jedis.JedisConnectionFactory&quot;
        p:host-name=&quot;${redis.host-name}&quot;
        p:port=&quot;${redis.port}&quot;
        p:use-pool=&quot;true&quot;/&gt;

    &lt;!-- redis template definition --&gt;
    &lt;bean
        id=&quot;redisTemplate&quot;
        class=&quot;org.springframework.data.redis.core.RedisTemplate&quot;
        p:connection-factory-ref=&quot;jedisConnectionFactory&quot;/&gt;

    &lt;!-- declare Redis Cache Manager --&gt;
    &lt;bean
        id=&quot;cacheManager&quot;
        class=&quot;org.springframework.data.redis.cache.RedisCacheManager&quot;
        c:template-ref=&quot;redisTemplate&quot;/&gt;

&lt;/beans&gt;
</pre>
<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>
<pre class="brush: java; title: AppConfig.java; notranslate">
package com.joshuawhite.example.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

@Configuration
@EnableCaching
@ComponentScan(&quot;com.joshuawhite.example&quot;)
@PropertySource(&quot;classpath:/redis.properties&quot;)
public class AppConfig {

 private @Value(&quot;${redis.host-name}&quot;) String redisHostName;
 private @Value(&quot;${redis.port}&quot;) int redisPort;

 @Bean
 public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
     return new PropertySourcesPlaceholderConfigurer();
 }

 @Bean
 JedisConnectionFactory jedisConnectionFactory() {
     JedisConnectionFactory factory = new JedisConnectionFactory();
     factory.setHostName(redisHostName);
     factory.setPort(redisPort);
     factory.setUsePool(true);
     return factory;
 }

 @Bean
 RedisTemplate&lt;Object, Object&gt; redisTemplate() {
     RedisTemplate&lt;Object, Object&gt; redisTemplate = new RedisTemplate&lt;Object, Object&gt;();
     redisTemplate.setConnectionFactory(jedisConnectionFactory());
     return redisTemplate;
 }

 @Bean
 CacheManager cacheManager() {
     return new RedisCacheManager(redisTemplate());
 }

}
</pre>
<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>
<pre class="brush: java; title: redis.properties; notranslate">
redis.host-name=yourHostNameHere
redis.port=6379
</pre>
<h3>Output</h3>
<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 &#8220;Joshua&#8221;.</p>
<p>When we call <code>getHelloMessage("Joshua")</code> for the first time, the method is executed.  The second time however, it is not.</p>
<pre class="brush: plain; title: Output; notranslate">
Executing HelloServiceImpl.getHelloMessage(&quot;Josh&quot;)
message: Hello Josh!
Executing HelloServiceImpl.getHelloMessage(&quot;Josh&quot;)
message: Hello Josh!
Executing HelloServiceImpl.getHelloMessage(&quot;Joshua&quot;)
message: Hello Joshua!
message: Hello Joshua!
Done.
</pre>
<p>This concludes our brief over view of caching with Spring Data Redis.</p>
<p>The post <a rel="nofollow" href="http://blog.joshuawhite.com/java/caching-with-spring-data-redis/">Caching with Spring Data Redis</a> appeared first on <a rel="nofollow" href="http://blog.joshuawhite.com">Joshua White&#039;s Blog</a>.</p>
]]></content:encoded>
			</item>
	</channel>
</rss>

<!-- Dynamic page generated in 2.215 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2016-09-10 12:52:59 -->
