public CasAuthenticationToken getByTicketId(final String serviceTicket) { final Element element = cache.get(serviceTicket); if (logger.isDebugEnabled()) { logger.debug("Cache hit: " + (element != null) + "; service ticket: " + serviceTicket); } return element == null ? null : (CasAuthenticationToken) element.getValue(); }
public UserDetails getUserFromCache(String username) { Element element = cache.get(username); if (logger.isDebugEnabled()) { logger.debug("Cache hit: " + (element != null) + "; username: " + username); } if (element == null) { return null; } else { return (UserDetails) element.getValue(); } }
public UserDetails getUserFromCache(String username) { Element element = cache.get(username); if (logger.isDebugEnabled()) { logger.debug("Cache hit: " + (element != null) + "; username: " + username); } if (element == null) { return null; } else { return (UserDetails) element.getValue(); } }
/** * Retrieve the missed cache item from the specified cache. * * @param key the unique key for the cache item * @param cacheName the name of the cache - this is the cache region name from ehcache config * @param <T> the type of the cache item * @return the cache item instance */ protected <T> T getObjectFromCache(String key, String cacheName) { Element cacheElement = getCache(cacheName).get(key); if (cacheElement != null) { return (T) cacheElement.getValue(); } return null; }
public MutableAcl getFromCache(ObjectIdentity objectIdentity) { Assert.notNull(objectIdentity, "ObjectIdentity required"); Element element = null; try { element = cache.get(objectIdentity); } catch (CacheException ignored) { } if (element == null) { return null; } return initializeTransientFields((MutableAcl) element.getValue()); }
public MutableAcl getFromCache(Serializable pk) { Assert.notNull(pk, "Primary key (identifier) required"); Element element = null; try { element = cache.get(pk); } catch (CacheException ignored) { } if (element == null) { return null; } return initializeTransientFields((MutableAcl) element.getValue()); }
@Override @SuppressWarnings("unchecked") public List<SearchFacetDTO> getSearchFacets() { List<SearchFacetDTO> facets = null; String cacheKey = CACHE_KEY_PREFIX + "blc-search"; Element element = cache.get(cacheKey); if (element != null) { facets = (List<SearchFacetDTO>) element.getValue(); } if (facets == null) { facets = buildSearchFacetDtos(searchFacetDao.readAllSearchFacets(FieldEntity.PRODUCT)); element = new Element(cacheKey, facets); cache.put(element); } return facets; }
@Override @SuppressWarnings("unchecked") public List<SearchFacetDTO> getCategoryFacets(Category category) { List<SearchFacetDTO> facets = null; String cacheKey = CACHE_KEY_PREFIX + "category:" + category.getId(); Element element = cache.get(cacheKey); if (element != null) { facets = (List<SearchFacetDTO>) element.getValue(); } if (facets == null) { List<CategorySearchFacet> categorySearchFacets = category.getCumulativeSearchFacets(); List<SearchFacet> searchFacets = new ArrayList<SearchFacet>(); for (CategorySearchFacet categorySearchFacet : categorySearchFacets) { searchFacets.add(categorySearchFacet.getSearchFacet()); } facets = buildSearchFacetDtos(searchFacets); element = new Element(cacheKey, facets); cache.put(element); } return facets; }
public Object processRequest(ProceedingJoinPoint call) throws Throwable { CacheRequest cacheRequest = (CacheRequest) call.getArgs()[0]; Cache cache = ((ServiceResponseCacheable) call.getTarget()).getCache(); List<Serializable> cacheItemResponses = new ArrayList<Serializable>(); Iterator<CacheItemRequest> itr = cacheRequest.getCacheItemRequests().iterator(); while(itr.hasNext()) { CacheItemRequest itemRequest = itr.next(); if (cache.isKeyInCache(itemRequest.key())) { cacheItemResponses.add(cache.get(itemRequest.key()).getValue()); itr.remove(); } } CacheResponse returnValue = (CacheResponse) call.proceed(); Object[] responses = new Object[cacheItemResponses.size() + returnValue.getCacheItemResponses().length]; responses = cacheItemResponses.toArray(responses); for (int j=0; j<returnValue.getCacheItemResponses().length; j++) { Element element = new Element(cacheRequest.getCacheItemRequests().get(j).key(), returnValue.getCacheItemResponses()[j]); cache.put(element); } System.arraycopy(returnValue.getCacheItemResponses(), 0, responses, cacheItemResponses.size(), returnValue.getCacheItemResponses().length); returnValue.setCacheItemResponses(responses); return returnValue; }
protected StructuredContentDTO getSingleStructuredContentFromCache(String key) { Element scElement = getStructuredContentCache().get(key); if (scElement != null) { statisticsService.addCacheStat(CacheStatType.STRUCTURED_CONTENT_CACHE_HIT_RATE.toString(), true); return (StructuredContentDTO) scElement.getValue(); } statisticsService.addCacheStat(CacheStatType.STRUCTURED_CONTENT_CACHE_HIT_RATE.toString(), false); return null; }
/** * An extremely expensive check to see if the value exists in the cache. This implementation is O(n). Ehcache * is not designed for efficient access in this manner. * <p> * This method is not synchronized. It is possible that an element may exist in the cache and be removed * before the check gets to it, or vice versa. Because it is slow to execute the probability of that this will * have happened. * * @param value to check for * @return true if an Element matching the key is found in the cache. No assertions are made about the state of the Element. */ public boolean isValueInCache(Object value) { for (Object key : getKeys()) { Element element = get(key); if (element != null) { Object elementValue = element.getValue(); if (elementValue == null) { if (value == null) { return true; } } else { if (elementValue.equals(value)) { return true; } } } } return false; }
final Element element = ehcache.get(file); if (element != null) { final Serializable value = element.getValue(); if (value != null && value instanceof Histogram) { histogram = (Histogram) value;
public ElementData(final Element element) { this.value = element.getValue(); this.version = element.getVersion(); this.creationTime = element.getCreationTime(); this.lastAccessTime = element.getLastAccessTime(); this.hitCount = element.getHitCount(); this.cacheDefaultLifespan = element.usesCacheDefaultLifespan(); this.lastUpdateTime = element.getLastUpdateTime(); }
@Override public Serializable get(String key) { Element e = cache.get(key); return null == e ? null : e.getValue(); }
@Override public Object get(String key) { Element e = cache.get(key); return (e == null) ? null : e.getValue(); }
@Override public Serializable get(String key) { Element element = cache.get(key); return element != null ? element.getValue() : null; }
@Override public UserRegistration getRegistrationForUserIndexKey(UserIndexKey key) { Element element = _cache.get(key); if (element == null) return null; return (UserRegistration) element.getValue(); }
continue; } else if (oldElement.getValue() instanceof SoftLockID) { SoftLockID softLockId = (SoftLockID) oldElement.getObjectValue();
@Override public synchronized long incr(String key, int by) { Element e = cache.get(key); if (e == null) { return -1; } long newValue = ((Number) e.getValue()).longValue() + by; Element newE = new Element(key, newValue); newE.setTimeToLive(e.getTimeToLive()); cache.put(newE); return newValue; }
private Serializable loadKey(Ehcache cache, Serializable key) { Element element = cache.get(key); delayForTest(key); Serializable value = null; if (element != null) { value = element.getValue(); } return value; }