/** * Remove all cache entries for the given query. */ public void clearQuery(Query query) { lock.lock(); try { final Query singleton = uniqueQueries.remove(query); if (singleton != null) { onEviction(singleton); } } finally { lock.unlock(); } }
void evictIfNecessary() { assert lock.isHeldByCurrentThread(); // under a lock to make sure that mostRecentlyUsedQueries and cache keep sync'ed if (requiresEviction()) { Iterator<Query> iterator = mostRecentlyUsedQueries.iterator(); do { final Query query = iterator.next(); final int size = mostRecentlyUsedQueries.size(); iterator.remove(); if (size == mostRecentlyUsedQueries.size()) { // size did not decrease, because the hash of the query changed since it has been // put into the cache throw new ConcurrentModificationException("Removal from the cache failed! This " + "is probably due to a query which has been modified after having been put into " + " the cache or a badly implemented clone(). Query class: [" + query.getClass() + "], query: [" + query + "]"); } onEviction(query); } while (iterator.hasNext() && requiresEviction()); } }
/** * Remove all cache entries for the given query. */ public synchronized void clearQuery(Query query) { final Query singleton = uniqueQueries.remove(query); if (singleton != null) { onEviction(singleton); } }
/** * Remove all cache entries for the given query. */ public synchronized void clearQuery(Query query) { final Query singleton = uniqueQueries.remove(query); if (singleton != null) { onEviction(singleton); } }
/** * Remove all cache entries for the given query. */ public void clearQuery(Query query) { lock.lock(); try { final Query singleton = uniqueQueries.remove(query); if (singleton != null) { onEviction(singleton); } } finally { lock.unlock(); } }
synchronized void evictIfNecessary() { // under a lock to make sure that mostRecentlyUsedQueries and cache keep sync'ed if (requiresEviction()) { Iterator<Query> iterator = mostRecentlyUsedQueries.iterator(); do { final Query query = iterator.next(); final int size = mostRecentlyUsedQueries.size(); iterator.remove(); if (size == mostRecentlyUsedQueries.size()) { // size did not decrease, because the hash of the query changed since it has been // put into the cache throw new ConcurrentModificationException("Removal from the cache failed! This " + "is probably due to a query which has been modified after having been put into " + " the cache or a badly implemented clone(). Query class: [" + query.getClass() + "], query: [" + query + "]"); } onEviction(query); } while (iterator.hasNext() && requiresEviction()); } }
synchronized void evictIfNecessary() { // under a lock to make sure that mostRecentlyUsedQueries and cache keep sync'ed if (requiresEviction()) { Iterator<Query> iterator = mostRecentlyUsedQueries.iterator(); do { final Query query = iterator.next(); final int size = mostRecentlyUsedQueries.size(); iterator.remove(); if (size == mostRecentlyUsedQueries.size()) { // size did not decrease, because the hash of the query changed since it has been // put into the cache throw new ConcurrentModificationException("Removal from the cache failed! This " + "is probably due to a query which has been modified after having been put into " + " the cache or a badly implemented clone(). Query class: [" + query.getClass() + "], query: [" + query + "]"); } onEviction(query); } while (iterator.hasNext() && requiresEviction()); } }
void evictIfNecessary() { assert lock.isHeldByCurrentThread(); // under a lock to make sure that mostRecentlyUsedQueries and cache keep sync'ed if (requiresEviction()) { Iterator<Query> iterator = mostRecentlyUsedQueries.iterator(); do { final Query query = iterator.next(); final int size = mostRecentlyUsedQueries.size(); iterator.remove(); if (size == mostRecentlyUsedQueries.size()) { // size did not decrease, because the hash of the query changed since it has been // put into the cache throw new ConcurrentModificationException("Removal from the cache failed! This " + "is probably due to a query which has been modified after having been put into " + " the cache or a badly implemented clone(). Query class: [" + query.getClass() + "], query: [" + query + "]"); } onEviction(query); } while (iterator.hasNext() && requiresEviction()); } }