| 26 | import static java.lang.System.Logger.Level.WARNING; |
| 27 | |
| 28 | final class RedisCache implements ServerCache { |
| 29 | |
| 30 | private static final System.Logger log = AppLog.getLogger(RedisCache.class); |
| 31 | |
| 32 | private static final String CURSOR_0 = "0"; |
| 33 | private static final byte[] CURSOR_0_BYTES = SafeEncoder.encode(CURSOR_0); |
| 34 | |
| 35 | private final Pool<Jedis> jedisPool; |
| 36 | private final String cacheKey; |
| 37 | private final EncodePrefixKey keyEncode; |
| 38 | private final Encode valueEncode; |
| 39 | private final SetParams expiration; |
| 40 | private final TimedMetric metricGet; |
| 41 | private final TimedMetric metricGetAll; |
| 42 | private final TimedMetric metricPut; |
| 43 | private final TimedMetric metricPutAll; |
| 44 | private final TimedMetric metricRemove; |
| 45 | private final TimedMetric metricRemoveAll; |
| 46 | private final TimedMetric metricClear; |
| 47 | private final CountMetric hitCount; |
| 48 | private final CountMetric missCount; |
| 49 | |
| 50 | RedisCache(Pool<Jedis> jedisPool, ServerCacheConfig config, Encode valueEncode) { |
| 51 | this.jedisPool = jedisPool; |
| 52 | this.cacheKey = config.getCacheKey(); |
| 53 | this.keyEncode = new EncodePrefixKey(config.getCacheKey()); |
| 54 | this.valueEncode = valueEncode; |
| 55 | this.expiration = expiration(config); |
| 56 | String namePrefix = "l2r." + config.getShortName(); |
| 57 | MetricFactory factory = MetricFactory.get(); |
| 58 | hitCount = factory.createCountMetric(namePrefix + ".hit"); |
| 59 | missCount = factory.createCountMetric(namePrefix + ".miss"); |
| 60 | metricGet = factory.createTimedMetric(namePrefix + ".get"); |
| 61 | metricGetAll = factory.createTimedMetric(namePrefix + ".getMany"); |
| 62 | metricPut = factory.createTimedMetric(namePrefix + ".put"); |
| 63 | metricPutAll = factory.createTimedMetric(namePrefix + ".putMany"); |
| 64 | metricRemove = factory.createTimedMetric(namePrefix + ".remove"); |
| 65 | metricRemoveAll = factory.createTimedMetric(namePrefix + ".removeMany"); |
| 66 | metricClear = factory.createTimedMetric(namePrefix + ".clear"); |
| 67 | } |
| 68 | |
| 69 | private SetParams expiration(ServerCacheConfig config) { |
| 70 | final ServerCacheOptions cacheOptions = config.getCacheOptions(); |
| 71 | if (cacheOptions != null) { |
| 72 | final int maxSecsToLive = cacheOptions.getMaxSecsToLive(); |
| 73 | if (maxSecsToLive > 0) { |
| 74 | return new SetParams().ex((long) maxSecsToLive); |
| 75 | } |
| 76 | } |
| 77 | return null; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public void visit(MetricVisitor visitor) { |
| 82 | hitCount.visit(visitor); |
| 83 | missCount.visit(visitor); |
| 84 | metricGet.visit(visitor); |
| 85 | metricGetAll.visit(visitor); |
nothing calls this directly
no test coverage detected
searching dependent graphs…