Refactor L2 cache tenant awareness - add TenantAwareCache

The design change is to use TenantAwareCache to deal with wrap/unwrap of tenant aware keys, removing any tenant awareness from the underlying cache implementations (DefaultServerCache, redis, hazelcast etc).
This commit is contained in:
Rob Bygrave committed 2022-04-07 15:26:21 +12:00
1 parent daf5220766
commit f5a779e18b
14 files changed
+314 -108

No files matched your search

@@ -139,7 +139,7 @@ final class RedisCacheFactory implements ServerCacheFactory {
RedisCache redisCache = createRedisCache(config);
boolean nearCache = config.getCacheOptions().isNearCache();
if (!nearCache) {
return redisCache;
return config.tenantAware(redisCache);
}
String cacheKey = config.getCacheKey();
@@ -147,7 +147,7 @@ final class RedisCacheFactory implements ServerCacheFactory {
near.periodicTrim(executor);
DuelCache duelCache = new DuelCache(near, redisCache, cacheKey, nearCacheNotify);
nearCacheMap.put(cacheKey, duelCache);
return duelCache;
return config.tenantAware(duelCache);
}
private RedisCache createRedisCache(ServerCacheConfig config) {
@@ -173,7 +173,7 @@ final class RedisCacheFactory implements ServerCacheFactory {
cache.periodicTrim(executor);
queryCaches.put(config.getCacheKey(), cache);
}
return cache;
return config.tenantAware(cache);
} finally {
lock.unlock();
}
@@ -40,14 +40,14 @@ public class ClusterTest {
foo.save();
DB.cacheManager().clearAll();
DB.getDefault().metaInfo().resetAllMetrics();
db.metaInfo().resetAllMetrics();
other.metaInfo().resetAllMetrics();
Person fooA = DB.find(Person.class, foo.getId());
allowAsyncMessaging(); // allow time for background cache load
Person fooB = other.find(Person.class, foo.getId());
DuelCache dualCacheA = (DuelCache) DB.cacheManager().beanCache(Person.class);
DuelCache dualCacheA = db.cacheManager().beanCache(Person.class).unwrap(DuelCache.class);
assertCounts(dualCacheA, 0, 1, 0, 1);
fooA = DB.find(Person.class, foo.getId());
assertCounts(dualCacheA, 1, 1, 0, 1);
@@ -55,7 +55,7 @@ public class ClusterTest {
fooA = DB.find(Person.class, foo.getId());
assertCounts(dualCacheA, 2, 1, 0, 1);
fooB = other.find(Person.class, foo.getId());
DuelCache dualCacheB = (DuelCache) other.cacheManager().beanCache(Person.class);
DuelCache dualCacheB = other.cacheManager().beanCache(Person.class).unwrap(DuelCache.class);
assertCounts(dualCacheB, 2, 1, 1, 0);
}
@@ -73,7 +73,7 @@ public class ClusterTest {
other.cacheManager().clearAll();
other.metaInfo().resetAllMetrics();
DuelCache dualCache = (DuelCache) other.cacheManager().beanCache(Person.class);
DuelCache dualCache = other.cacheManager().beanCache(Person.class).unwrap(DuelCache.class);
Person foo0 = other.find(Person.class, 1);
assertCounts(dualCache, 0, 1, 0, 1);