Skip to content

levyfan/guava-cache-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

guava-cache-redis

Implement guava cache interface backed by redis. Guava provide memory cache implementation. We provide redis cache implementation.

Please read guava caches explained first.

Howto

<dependency>
    <groupId>com.github.levyfan</groupId>
    <artifactId>guava-cache-redis</artifactId>
    <version>0.0.2</version>
</dependency>
RedisCache<Key, Graph> redisCache = new RedisCache<>(
  jedisPool,
  keySerializer,
  valueSerializer,
  keyPrefix,
  expiration,
  new CacheLoader<Key, Graph>() {
    public Graph load(Key key) throws AnyException {
      return createExpensiveGraph(key);
    }
  }
);
...

try {
  return redisCache.get(key);
} catch (ExecutionException e) {
  throw new OtherException(e.getCause());
}

From a Callable

RedisCache<Key, Graph> redisCache = new RedisCache<>(
  jedisPool,
  keySerializer,
  valueSerializer,
  keyPrefix,
  expiration
);
...

try {
  // If the key wasn't in the "easy to compute" group, we need to do things the hard way.
  redisCache.get(key, new Callable<Value>() {
    @Override
    public Value call() throws AnyException {
      return doThingsTheHardWay(key);
    }
  });
} catch (ExecutionException e) {
  throw new OtherException(e.getCause());
}

About

implement guava cache interface backed by redis

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published