1 package com.atlassian.vcache.internal.core;
2
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
5
6 import static com.atlassian.vcache.internal.NameValidator.requireValidProductIdentifier;
7
8
9
10
11
12
13 public abstract class ExternalCacheKeyGenerator {
14 private static final Logger log = LoggerFactory.getLogger(ExternalCacheKeyGenerator.class);
15
16 private static final String SEPARATOR = "::";
17 private static final String CACHE_VERSION_KEY = "cache-version";
18
19 private final String productIdentifier;
20
21 public ExternalCacheKeyGenerator(String productIdentifier) {
22 this.productIdentifier = requireValidProductIdentifier(productIdentifier);
23 }
24
25
26
27
28 public String entryKey(String partition, String cacheName, long cacheVersion, String entryKey) {
29 final String plain = productIdentifier + SEPARATOR + partition + SEPARATOR + cacheName
30 + SEPARATOR + cacheVersion + SEPARATOR + entryKey;
31 final String encoded = encode(plain);
32 log.trace("Encoded cacheKey {} to {}", plain, encoded);
33 return encoded;
34 }
35
36
37
38
39 public String cacheVersionKey(String partition, String cacheName) {
40 final String plain = productIdentifier + SEPARATOR + partition + SEPARATOR + cacheName
41 + SEPARATOR + CACHE_VERSION_KEY;
42 final String encoded = encode(plain);
43 log.trace("Encoded cacheVersionKey {} to {}", plain, encoded);
44 return encoded;
45 }
46
47
48
49
50
51
52
53 protected abstract String encode(String plain);
54 }