@Override public ClassMap put(final Class clazz) { return classMapCache.get(clazz); }
private void recache() { getCache().put(cacheKey, delegate); } }
@Override public void refreshConfigurationSchemes(Long customFieldId) { fieldConfigSchemeManager.init(); customFieldsById.remove(customFieldId); }
private void clearCache() { if (log.isDebugEnabled()) { log.debug("Clearing issue security scheme cache, had " + schemeIdToSecuritiesCache.getKeys().size() + " scheme(s) and " + securityLevelToPermissionsCache.getKeys().size() + " security level(s)"); } schemeIdToSecuritiesCache.removeAll(); securityLevelToPermissionsCache.removeAll(); }
public Object retrieve(BandanaContext context, String key) { PersisterKey persisterKey = new PersisterKey(context, key); if (cache.get(persisterKey) == null) { synchronized (cache) { Object value = delegatedPersister.retrieve(context, key); cache.put(persisterKey, value); } } return cache.get(persisterKey); }
@ClusterSafe ( "We walk the keys of this map with the knowledge this is a canonical pinned cache of all existing tasks.") private Collection<? extends TaskDescriptorImpl<?>> getTasks(final Cache<Long, TaskDescriptorImpl<?>> taskMap) { List<TaskDescriptorImpl<?>> tasks = new ArrayList<TaskDescriptorImpl<?>>(); for (Long taskId : taskMap.getKeys()) { final TaskDescriptorImpl<?> taskDescriptor = taskMap.get(taskId); if (taskDescriptor != null) { tasks.add(taskDescriptor); } } return tasks; }
@Test public void testRemove() throws Exception { Cache<String, Long> cache = makeUnexpiringCache(); // Add some entries using the builder cache.put("1", 11L); cache.put("2", 12L); cache.put("3", 13L); cache.put("4", 14L); assertThat(cache.get("1"), equalTo(11L)); assertThat(cache.get("2"), equalTo(12L)); assertThat(cache.get("3"), equalTo(13L)); assertThat(cache.get("4"), equalTo(14L)); assertSize(cache, (4)); cache.remove("1"); cache.remove("2"); cache.remove("3"); assertSize(cache, (1)); assertThat(cache.containsKey("1"), is(false)); assertThat(cache.containsKey("2"), is(false)); assertThat(cache.containsKey("3"), is(false)); // Removed values should be recomputed assertThat(cache.get("1"), equalTo(1L)); assertThat(cache.get("2"), equalTo(2L)); assertThat(cache.get("3"), equalTo(3L)); assertThat(cache.get("4"), equalTo(14L)); assertSize(cache, (4)); }
@Override public void clear() { classMapCache.removeAll(); }
@Nonnull private RemoteApplicationCapabilities updateAndGet(@Nonnull ApplicationId id, @Nullable CachedCapabilities currentCapabilities, @Nonnull CachedCapabilities newCapabilities) { // these gymnastics are here to minimize cache access CachedCapabilities capabilitiesAnswer; if (currentCapabilities != null) { // previous value should exist in cache boolean successfulUpdate = capabilitiesCache.replace(id, currentCapabilities, newCapabilities); // if update was successful simply return newCapabilities, otherwise someone has updated the cache while we // were refreshing the value - grab those from cache capabilitiesAnswer = successfulUpdate ? newCapabilities : capabilitiesCache.get(id); } else { // previous capabilities did not exist, putIfAbsent to not override in case of concurrent write capabilitiesAnswer = capabilitiesCache.putIfAbsent(id, newCapabilities); } // final nonnull guard - in case values from cache were null for any reason, use newCapabilities as a return // value capabilitiesAnswer = capabilitiesAnswer == null ? newCapabilities : capabilitiesAnswer; getRequestCache().put(id, capabilitiesAnswer); return capabilitiesAnswer.capabilities; }
@Test public void conditionalPutDoesNotPutIfPresent() { Cache<String, Long> cache = makeSimpleCache(); cache.putIfAbsent("A", 1L); assertEquals(Long.valueOf(1), cache.putIfAbsent("A", 2L)); assertEquals(Long.valueOf(1), cache.get("A")); }
public Collection<K> getKeys() { return cache.getKeys(); }
@Override public EnclosedIterable<SearchRequest> get(final RetrievalDescriptor descriptor) { // get SearchRequests that haven't been loaded to the cache yet and populate the cache final DefaultSharedEntitySearcher.Ids searchRequestsFromDb = new DefaultSharedEntitySearcher.Ids( descriptor.getIds().stream().filter(id -> !cacheById.containsKey(id)) .collect(toImmutableListWithSizeOf(descriptor.getIds())), false); delegateStore.get(searchRequestsFromDb).foreach(searchRequest -> cacheById.put(searchRequest.getId(), CacheObject.wrap(searchRequest))); // read all from the cache return CollectionEnclosedIterable.from(descriptor.getIds().stream().filter(cacheById::containsKey).map(cacheById::get).filter(CacheObject::hasValue) .map(CacheObject::getValue).collect(toImmutableListWithSizeOf(descriptor.getIds()))); }
@Override public V putIfAbsent(@Nonnull K key, @Nonnull V value) { V oldValue = localCache.putIfAbsent(key, value); if (oldValue == null) { invalidateRemotely(key); } return oldValue; }
@Override public boolean containsKey(@Nonnull final K k) { return localCache.containsKey(k); }
@Override public String toString() { final StringBuilder sb = new StringBuilder(1024).append(getClass().getSimpleName()).append("[entries={"); final Collection<CacheKey> keys = entries.getKeys(); if (!keys.isEmpty()) { for (CacheKey key : keys) { sb.append("\n\t").append(key).append(" => ").append(entries.get(key)).append(','); } // Change the last comma to a newline sb.setCharAt(sb.length() - 1, '\n'); } return sb.append("}]").toString(); }