Skip to content

ww9xlll/guava-cache-lettuce

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

guava-cache-lettuce

Implement guava cache interface backed by redis (lettuce or jedis). Guava provide memory cache implementation. We provide redis cache implementation.

Please read guava caches explained first.

Howto

<dependency>
    <groupId>io.github.thinkdiffw</groupId>
    <artifactId>guava-cache-lettuce</artifactId>
    <version>0.0.4</version>
</dependency>
LettuceCache<Key, Graph> redisCache = new LettuceCache<>(
  connection,
  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

LettuceCache<Key, Graph> redisCache = new LettuceCache<>(
  connection,
  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 lettuce

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published