@Override public void put(Object key, @Nullable Object value) { this.cache.put(new Element(key, value)); }
@Override public <K, V> void put(K key, V value) { ehCache.put(new Element(key, value)); }
public void put(Object key, Object value) { this.cache.put(new Element(key, value)); }
@Override public void put(Object key, @Nullable Object value) { this.cache.put(new Element(key, value)); }
private void put(String key, Object value, Predicate predicate) { logUnsavedPersistentObjectInteraction(value, "PersistentObject {} added to cache without an id."); if (predicate.isTrue()) { LOGGER.debug("transaction active during cache put for {} = {}", key, value, new IllegalStateException()); return; } ehCache.put(new Element(key, value)); }
public void putTicketInCache(final CasAuthenticationToken token) { final Element element = new Element(token.getCredentials().toString(), token); if (logger.isDebugEnabled()) { logger.debug("Cache put: " + element.getKey()); } cache.put(element); }
public <T> T get(String key, Supplier<T> compute) { Element element = ehcache.get(key); if (element != null) { return (T) element.getObjectValue(); } synchronized (key.intern()) { element = ehcache.get(key); if (element != null) { return (T) element.getObjectValue(); } T object = compute.get(); ehcache.put(new Element(key, object)); return object; } }
public void putUserInCache(UserDetails user) { Element element = new Element(user.getUsername(), user); if (logger.isDebugEnabled()) { logger.debug("Cache put: " + element.getKey()); } cache.put(element); }
public void putUserInCache(UserDetails user) { Element element = new Element(user.getUsername(), user); if (logger.isDebugEnabled()) { logger.debug("Cache put: " + element.getKey()); } cache.put(element); }
@Override public void save(final Session session) { Map<String, String> attributes = new HashMap<>(session.attributes()); attributes.put("_accessedAt", Long.toString(session.accessedAt())); attributes.put("_createdAt", Long.toString(session.createdAt())); attributes.put("_savedAt", Long.toString(session.savedAt())); cache.put(new Element(session.id(), attributes)); }
@Override public Object extractPrincipal(X509Certificate cert) { try { Element element = cache.get(cert); if (element != null) { return element.getObjectValue(); } } catch (CacheException cacheException) { throw new DataRetrievalFailureException("Cache failure: " + cacheException.getMessage()); } final Object principal = delegate.extractPrincipal(cert); cache.put(new Element(cert, principal)); return principal; } }
/** * Puts an object into the cache. * * @param key the key. * @param value the value. */ public V put(K key, V value) throws CacheException { if (log.isTraceEnabled()) { log.trace("Putting object in cache [" + cache.getName() + "] for key [" + key + "]"); } try { V previous = get(key); Element element = new Element(key, value); cache.put(element); return previous; } catch (Throwable t) { throw new CacheException(t); } }
public void putInCache(MutableAcl acl) { Assert.notNull(acl, "Acl required"); Assert.notNull(acl.getObjectIdentity(), "ObjectIdentity required"); Assert.notNull(acl.getId(), "ID required"); if (this.aclAuthorizationStrategy == null) { if (acl instanceof AclImpl) { this.aclAuthorizationStrategy = (AclAuthorizationStrategy) FieldUtils .getProtectedFieldValue("aclAuthorizationStrategy", acl); this.permissionGrantingStrategy = (PermissionGrantingStrategy) FieldUtils .getProtectedFieldValue("permissionGrantingStrategy", acl); } } if ((acl.getParentAcl() != null) && (acl.getParentAcl() instanceof MutableAcl)) { putInCache((MutableAcl) acl.getParentAcl()); } cache.put(new Element(acl.getObjectIdentity(), acl)); cache.put(new Element(acl.getId(), acl)); }
@Test public void putInCache() throws Exception { myCache.putInCache(acl); verify(cache, times(2)).put(element.capture()); assertThat(element.getValue().getKey()).isEqualTo(acl.getId()); assertThat(element.getValue().getObjectValue()).isEqualTo(acl); assertThat(element.getAllValues().get(0).getKey()).isEqualTo( acl.getObjectIdentity()); assertThat(element.getAllValues().get(0).getObjectValue()).isEqualTo(acl); }
@Override public void putIntoCache(Object key, Object value, SharedSessionContractImplementor session) { try { final Element element = new Element( key, value ); getCache().put( element ); } catch (IllegalArgumentException | IllegalStateException e) { throw new CacheException( e ); } catch (net.sf.ehcache.CacheException e) { if ( e instanceof NonStopCacheException ) { HibernateNonstopCacheExceptionHandler.getInstance() .handleNonstopCacheException( (NonStopCacheException) e ); } else { throw new CacheException( e ); } } }
@Test public void putInCacheAclWithParent() throws Exception { Authentication auth = new TestingAuthenticationToken("user", "password", "ROLE_GENERAL"); auth.setAuthenticated(true); SecurityContextHolder.getContext().setAuthentication(auth); ObjectIdentity identityParent = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(2)); AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl( new SimpleGrantedAuthority("ROLE_OWNERSHIP"), new SimpleGrantedAuthority( "ROLE_AUDITING"), new SimpleGrantedAuthority("ROLE_GENERAL")); MutableAcl parentAcl = new AclImpl(identityParent, Long.valueOf(2), aclAuthorizationStrategy, new ConsoleAuditLogger()); acl.setParent(parentAcl); myCache.putInCache(acl); verify(cache, times(4)).put(element.capture()); List<Element> allValues = element.getAllValues(); assertThat(allValues.get(0).getKey()).isEqualTo(parentAcl.getObjectIdentity()); assertThat(allValues.get(0).getObjectValue()).isEqualTo(parentAcl); assertThat(allValues.get(1).getKey()).isEqualTo(parentAcl.getId()); assertThat(allValues.get(1).getObjectValue()).isEqualTo(parentAcl); assertThat(allValues.get(2).getKey()).isEqualTo(acl.getObjectIdentity()); assertThat(allValues.get(2).getObjectValue()).isEqualTo(acl); assertThat(allValues.get(3).getKey()).isEqualTo(acl.getId()); assertThat(allValues.get(3).getObjectValue()).isEqualTo(acl); }
@Test public void testExpiredElements() throws Exception { Assume.group(TestGroup.LONG_RUNNING); String key = "brancusi"; String value = "constantin"; Element brancusi = new Element(key, value); // ttl = 10s brancusi.setTimeToLive(3); nativeCache.put(brancusi); assertEquals(value, cache.get(key).get()); // wait for the entry to expire Thread.sleep(5 * 1000); assertNull(cache.get(key)); }
@Override public Void put() { underlyingCache.put(element, doNotNotifyCacheReplicators); return null; } });
@Override public Void put() { if (element.getObjectValue() != null) { underlyingCache.put(element); } else { underlyingCache.remove(element.getObjectKey()); } return null; } });
private void saveOrUpdate(ApiKey apiKey) { if (apiKey.isRevoked() || apiKey.isPaused()) { logger.debug("Remove a paused / revoked api-key from cache [key: {}] [plan: {}] [app: {}]", apiKey.getKey(), apiKey.getPlan(), apiKey.getApplication()); cache.remove(apiKey.getKey()); } else { logger.debug("Cache an api-key [key: {}] [plan: {}] [app: {}]", apiKey.getKey(), apiKey.getPlan(), apiKey.getApplication()); cache.put(new Element(apiKey.getKey(), apiKey)); } }