Skip to content

Instantly share code, notes, and snippets.

@davetownsend
Last active June 29, 2018 05:13

Revisions

  1. davetownsend revised this gist Jul 23, 2014. No changes.
  2. davetownsend revised this gist Jul 23, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -48,7 +48,7 @@ private CacheConfiguration cacheConfig(String name, long maxEntries) {


    Make sure to add the following gradle dependencies:
    compile "org.springframework:spring-context-support:4.0.6.RELEASE"
    compile 'org.springframework:spring-context-support:4.0.6.RELEASE'
    compile 'net.sf.ehcache:ehcache:2.8.3'

    If you use maven you'll just have figure it out.
  3. davetownsend revised this gist Jul 23, 2014. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -48,8 +48,7 @@ private CacheConfiguration cacheConfig(String name, long maxEntries) {


    Make sure to add the following gradle dependencies:
    ```
    compile "org.springframework:spring-context-support:4.0.6.RELEASE"
    compile 'net.sf.ehcache:ehcache:2.8.3'
    ```

    If you use maven you'll just have figure it out.
  4. davetownsend created this gist Jul 23, 2014.
    55 changes: 55 additions & 0 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    package org.dt.cachetest;

    import net.sf.ehcache.config.CacheConfiguration;
    import org.springframework.cache.annotation.CachingConfigurer;
    import org.springframework.cache.annotation.EnableCaching;
    import org.springframework.cache.ehcache.EhCacheCacheManager;
    import org.springframework.cache.interceptor.KeyGenerator;
    import org.springframework.cache.interceptor.SimpleKeyGenerator;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Configuration;

    @Configuration
    @EnableCaching
    @ComponentScan("org.dt.cachetest")
    public class EhCacheConfig implements CachingConfigurer {

    final static String CACHE_POLICY = "LRU";

    @Bean(destroyMethod = "shutdown")
    public net.sf.ehcache.CacheManager ehCacheManager() {
    net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
    config.addCache(cacheConfig("cache1", 500));
    config.addCache(cacheConfig("cache2", 500));
    return net.sf.ehcache.CacheManager.newInstance(config);
    }

    @Bean
    @Override
    public org.springframework.cache.CacheManager cacheManager() {
    return new EhCacheCacheManager(ehCacheManager());
    }

    @Bean
    @Override
    public KeyGenerator keyGenerator() {
    return new SimpleKeyGenerator();
    }

    private CacheConfiguration cacheConfig(String name, long maxEntries) {
    CacheConfiguration config = new CacheConfiguration();
    config.setName(name);
    config.setMaxEntriesLocalHeap(maxEntries);
    config.setMemoryStoreEvictionPolicy(CACHE_POLICY);
    return config;
    }
    }


    Make sure to add the following gradle dependencies:
    ```
    compile "org.springframework:spring-context-support:4.0.6.RELEASE"
    compile 'net.sf.ehcache:ehcache:2.8.3'
    ```
    If you use maven you'll just have figure it out.