guava-cache-redis

implement guava cache interface backed by redis

License

License

Categories

Categories

Redis Data Databases Guava General Purpose Libraries Utility
GroupId

GroupId

com.github.levyfan
ArtifactId

ArtifactId

guava-cache-redis
Last Version

Last Version

0.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

guava-cache-redis
implement guava cache interface backed by redis
Project URL

Project URL

https://github.com/levyfan/guava-cache-redis
Source Code Management

Source Code Management

https://github.com/levyfan/guava-cache-redis

Download guava-cache-redis

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.levyfan/guava-cache-redis/ -->
<dependency>
    <groupId>com.github.levyfan</groupId>
    <artifactId>guava-cache-redis</artifactId>
    <version>0.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.levyfan/guava-cache-redis/
implementation 'com.github.levyfan:guava-cache-redis:0.0.2'
// https://jarcasting.com/artifacts/com.github.levyfan/guava-cache-redis/
implementation ("com.github.levyfan:guava-cache-redis:0.0.2")
'com.github.levyfan:guava-cache-redis:jar:0.0.2'
<dependency org="com.github.levyfan" name="guava-cache-redis" rev="0.0.2">
  <artifact name="guava-cache-redis" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.levyfan', module='guava-cache-redis', version='0.0.2')
)
libraryDependencies += "com.github.levyfan" % "guava-cache-redis" % "0.0.2"
[com.github.levyfan/guava-cache-redis "0.0.2"]

Dependencies

compile (3)

Group / Artifact Type Version
com.google.guava : guava jar 19.0
redis.clients : jedis jar 2.8.0
org.apache.commons : commons-lang3 jar 3.4

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

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>

From a CacheLoader

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());
}

Versions

Version
0.0.2