more fine tuning
This commit is contained in:
parent
1511f7088f
commit
daa09f9a41
3 changed files with 24 additions and 32 deletions
|
@ -313,7 +313,7 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RealmModel getRealmByName(String name) {
|
public RealmModel getRealmByName(String name) {
|
||||||
String cacheKey = "realm.query.by.name." + name;
|
String cacheKey = getRealmByNameCacheKey(name);
|
||||||
RealmListQuery query = cache.get(cacheKey, RealmListQuery.class);
|
RealmListQuery query = cache.get(cacheKey, RealmListQuery.class);
|
||||||
if (query != null) {
|
if (query != null) {
|
||||||
logger.tracev("realm by name cache hit: {0}", name);
|
logger.tracev("realm by name cache hit: {0}", name);
|
||||||
|
@ -337,6 +337,10 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRealmByNameCacheKey(String name) {
|
||||||
|
return "realm.query.by.name." + name;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<RealmModel> getRealms() {
|
public List<RealmModel> getRealms() {
|
||||||
// Retrieve realms from backend
|
// Retrieve realms from backend
|
||||||
|
@ -353,9 +357,11 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeRealm(String id) {
|
public boolean removeRealm(String id) {
|
||||||
if (getRealm(id) == null) return false;
|
RealmModel realm = getRealm(id);
|
||||||
|
if (realm == null) return false;
|
||||||
|
|
||||||
invalidations.add(getRealmClientsQueryCacheKey(id));
|
invalidations.add(getRealmClientsQueryCacheKey(id));
|
||||||
|
invalidations.add(getRealmByNameCacheKey(realm.getName()));
|
||||||
cache.invalidateObject(id);
|
cache.invalidateObject(id);
|
||||||
cache.realmRemoval(id, invalidations);
|
cache.realmRemoval(id, invalidations);
|
||||||
return getDelegate().removeRealm(id);
|
return getDelegate().removeRealm(id);
|
||||||
|
@ -379,6 +385,7 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
|
||||||
invalidations.add(getRealmClientsQueryCacheKey(realm.getId()));
|
invalidations.add(getRealmClientsQueryCacheKey(realm.getId()));
|
||||||
invalidations.add(client.getId());
|
invalidations.add(client.getId());
|
||||||
cache.clientAdded(realm.getId(), client.getId(), invalidations);
|
cache.clientAdded(realm.getId(), client.getId(), invalidations);
|
||||||
|
// this is needed so that a new client that hasn't been committed isn't cached in a query
|
||||||
clientListInvalidations.add(realm.getId());
|
clientListInvalidations.add(realm.getId());
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
@ -429,6 +436,7 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
|
||||||
if (client == null) return false;
|
if (client == null) return false;
|
||||||
// need to invalidate realm client query cache every time client list is changed
|
// need to invalidate realm client query cache every time client list is changed
|
||||||
invalidations.add(getRealmClientsQueryCacheKey(realm.getId()));
|
invalidations.add(getRealmClientsQueryCacheKey(realm.getId()));
|
||||||
|
invalidations.add(getClientByClientIdCacheKey(client.getClientId(), realm));
|
||||||
clientListInvalidations.add(realm.getId());
|
clientListInvalidations.add(realm.getId());
|
||||||
registerClientInvalidation(id);
|
registerClientInvalidation(id);
|
||||||
cache.clientRemoval(realm.getId(), id, invalidations);
|
cache.clientRemoval(realm.getId(), id, invalidations);
|
||||||
|
@ -527,7 +535,7 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClientModel getClientByClientId(String clientId, RealmModel realm) {
|
public ClientModel getClientByClientId(String clientId, RealmModel realm) {
|
||||||
String cacheKey = realm.getId() + ".client.query.by.clientId." + clientId;
|
String cacheKey = getClientByClientIdCacheKey(clientId, realm);
|
||||||
ClientListQuery query = cache.get(cacheKey, ClientListQuery.class);
|
ClientListQuery query = cache.get(cacheKey, ClientListQuery.class);
|
||||||
String id = null;
|
String id = null;
|
||||||
|
|
||||||
|
@ -555,6 +563,10 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
|
||||||
return getClientById(id, realm);
|
return getClientById(id, realm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getClientByClientIdCacheKey(String clientId, RealmModel realm) {
|
||||||
|
return realm.getId() + ".client.query.by.clientId." + clientId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClientTemplateModel getClientTemplateById(String id, RealmModel realm) {
|
public ClientTemplateModel getClientTemplateById(String id, RealmModel realm) {
|
||||||
CachedClientTemplate cached = cache.get(id, CachedClientTemplate.class);
|
CachedClientTemplate cached = cache.get(id, CachedClientTemplate.class);
|
||||||
|
|
|
@ -146,6 +146,9 @@ public class StreamRealmCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
cache.clear();
|
cache.clear();
|
||||||
}
|
}
|
||||||
|
@ -253,7 +256,7 @@ public class StreamRealmCache {
|
||||||
|
|
||||||
@CacheEntryInvalidated
|
@CacheEntryInvalidated
|
||||||
public void cacheInvalidated(CacheEntryInvalidatedEvent<String, Object> event) {
|
public void cacheInvalidated(CacheEntryInvalidatedEvent<String, Object> event) {
|
||||||
if (event.isPre()) {
|
if (!event.isPre()) {
|
||||||
Object object = event.getValue();
|
Object object = event.getValue();
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
Predicate<Map.Entry<String, Revisioned>> predicate = getInvalidationPredicate(object);
|
Predicate<Map.Entry<String, Revisioned>> predicate = getInvalidationPredicate(object);
|
||||||
|
@ -264,8 +267,9 @@ public class StreamRealmCache {
|
||||||
|
|
||||||
@CacheEntriesEvicted
|
@CacheEntriesEvicted
|
||||||
public void cacheEvicted(CacheEntriesEvictedEvent<String, Object> event) {
|
public void cacheEvicted(CacheEntriesEvictedEvent<String, Object> event) {
|
||||||
|
if (!event.isPre())
|
||||||
for (Object object : event.getEntries().values()) {
|
for (Object object : event.getEntries().values()) {
|
||||||
Predicate<Map.Entry<String, Revisioned>> predicate = getEvictionPredicate(object);
|
Predicate<Map.Entry<String, Revisioned>> predicate = getInvalidationPredicate(object);
|
||||||
if (predicate != null) runEvictions(predicate);
|
if (predicate != null) runEvictions(predicate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -276,25 +280,6 @@ public class StreamRealmCache {
|
||||||
for (String key : evictions) cache.evict(key);
|
for (String key : evictions) cache.evict(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Predicate<Map.Entry<String, Revisioned>> getEvictionPredicate(Object object) {
|
|
||||||
if (object instanceof CachedRealm) {
|
|
||||||
CachedRealm cached = (CachedRealm)object;
|
|
||||||
return getRealmInvalidationPredicate(cached.getId());
|
|
||||||
} else if (object instanceof CachedClient) {
|
|
||||||
CachedClient cached = (CachedClient)object;
|
|
||||||
return getClientInvalidationPredicate(cached.getId());
|
|
||||||
} else if (object instanceof CachedRole) {
|
|
||||||
CachedRole cached = (CachedRole)object;
|
|
||||||
return getRoleInvalidationPredicate(cached.getId());
|
|
||||||
} else if (object instanceof CachedGroup) {
|
|
||||||
CachedGroup cached = (CachedGroup)object;
|
|
||||||
return getGroupInvalidationPredicate(cached.getId());
|
|
||||||
} else if (object instanceof CachedClientTemplate) {
|
|
||||||
CachedClientTemplate cached = (CachedClientTemplate)object;
|
|
||||||
return getClientTemplateInvalidationPredicate(cached.getId());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
protected Predicate<Map.Entry<String, Revisioned>> getInvalidationPredicate(Object object) {
|
protected Predicate<Map.Entry<String, Revisioned>> getInvalidationPredicate(Object object) {
|
||||||
if (object instanceof CachedRealm) {
|
if (object instanceof CachedRealm) {
|
||||||
CachedRealm cached = (CachedRealm)object;
|
CachedRealm cached = (CachedRealm)object;
|
||||||
|
|
|
@ -64,22 +64,17 @@ public class ClusteredCacheBehaviorTest {
|
||||||
|
|
||||||
@CacheEntryRemoved
|
@CacheEntryRemoved
|
||||||
public void removed(CacheEntryRemovedEvent<String, Object> event) {
|
public void removed(CacheEntryRemovedEvent<String, Object> event) {
|
||||||
if (event.isPre()) {
|
System.out.println("Listener '" + name + "' entry removed isPre: " + event.isPre());
|
||||||
System.out.println("Listener '" + name + "' entry removed");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@CacheEntryInvalidated
|
@CacheEntryInvalidated
|
||||||
public void removed(CacheEntryInvalidatedEvent<String, Object> event) {
|
public void removed(CacheEntryInvalidatedEvent<String, Object> event) {
|
||||||
if (event.isPre()) {
|
System.out.println("Listener '" + name + "' entry invalidated: isPre: " + event.isPre());
|
||||||
System.out.println("Listener '" + name + "' entry invalidated");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@CacheEntriesEvicted
|
@CacheEntriesEvicted
|
||||||
public void evicted(CacheEntriesEvictedEvent<String, Object> event) {
|
public void evicted(CacheEntriesEvictedEvent<String, Object> event) {
|
||||||
System.out.println("Listener '" + name + "' entry evicted");
|
System.out.println("Listener '" + name + "' entry evicted isPre: " + event.isPre());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue