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
|
||||
public RealmModel getRealmByName(String name) {
|
||||
String cacheKey = "realm.query.by.name." + name;
|
||||
String cacheKey = getRealmByNameCacheKey(name);
|
||||
RealmListQuery query = cache.get(cacheKey, RealmListQuery.class);
|
||||
if (query != null) {
|
||||
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
|
||||
public List<RealmModel> getRealms() {
|
||||
// Retrieve realms from backend
|
||||
|
@ -353,9 +357,11 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
|
|||
|
||||
@Override
|
||||
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(getRealmByNameCacheKey(realm.getName()));
|
||||
cache.invalidateObject(id);
|
||||
cache.realmRemoval(id, invalidations);
|
||||
return getDelegate().removeRealm(id);
|
||||
|
@ -379,6 +385,7 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
|
|||
invalidations.add(getRealmClientsQueryCacheKey(realm.getId()));
|
||||
invalidations.add(client.getId());
|
||||
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());
|
||||
return client;
|
||||
}
|
||||
|
@ -429,6 +436,7 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
|
|||
if (client == null) return false;
|
||||
// need to invalidate realm client query cache every time client list is changed
|
||||
invalidations.add(getRealmClientsQueryCacheKey(realm.getId()));
|
||||
invalidations.add(getClientByClientIdCacheKey(client.getClientId(), realm));
|
||||
clientListInvalidations.add(realm.getId());
|
||||
registerClientInvalidation(id);
|
||||
cache.clientRemoval(realm.getId(), id, invalidations);
|
||||
|
@ -527,7 +535,7 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
|
|||
|
||||
@Override
|
||||
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);
|
||||
String id = null;
|
||||
|
||||
|
@ -555,6 +563,10 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
|
|||
return getClientById(id, realm);
|
||||
}
|
||||
|
||||
public String getClientByClientIdCacheKey(String clientId, RealmModel realm) {
|
||||
return realm.getId() + ".client.query.by.clientId." + clientId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientTemplateModel getClientTemplateById(String id, RealmModel realm) {
|
||||
CachedClientTemplate cached = cache.get(id, CachedClientTemplate.class);
|
||||
|
|
|
@ -146,6 +146,9 @@ public class StreamRealmCache {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void clear() {
|
||||
cache.clear();
|
||||
}
|
||||
|
@ -253,7 +256,7 @@ public class StreamRealmCache {
|
|||
|
||||
@CacheEntryInvalidated
|
||||
public void cacheInvalidated(CacheEntryInvalidatedEvent<String, Object> event) {
|
||||
if (event.isPre()) {
|
||||
if (!event.isPre()) {
|
||||
Object object = event.getValue();
|
||||
if (object != null) {
|
||||
Predicate<Map.Entry<String, Revisioned>> predicate = getInvalidationPredicate(object);
|
||||
|
@ -264,8 +267,9 @@ public class StreamRealmCache {
|
|||
|
||||
@CacheEntriesEvicted
|
||||
public void cacheEvicted(CacheEntriesEvictedEvent<String, Object> event) {
|
||||
if (!event.isPre())
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -276,25 +280,6 @@ public class StreamRealmCache {
|
|||
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) {
|
||||
if (object instanceof CachedRealm) {
|
||||
CachedRealm cached = (CachedRealm)object;
|
||||
|
|
|
@ -64,22 +64,17 @@ public class ClusteredCacheBehaviorTest {
|
|||
|
||||
@CacheEntryRemoved
|
||||
public void removed(CacheEntryRemovedEvent<String, Object> event) {
|
||||
if (event.isPre()) {
|
||||
System.out.println("Listener '" + name + "' entry removed");
|
||||
}
|
||||
System.out.println("Listener '" + name + "' entry removed isPre: " + event.isPre());
|
||||
}
|
||||
|
||||
@CacheEntryInvalidated
|
||||
public void removed(CacheEntryInvalidatedEvent<String, Object> event) {
|
||||
if (event.isPre()) {
|
||||
System.out.println("Listener '" + name + "' entry invalidated");
|
||||
|
||||
}
|
||||
System.out.println("Listener '" + name + "' entry invalidated: isPre: " + event.isPre());
|
||||
}
|
||||
|
||||
@CacheEntriesEvicted
|
||||
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