本文整理了Java中net.sf.ehcache.Ehcache.put()
方法的一些代码示例,展示了Ehcache.put()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ehcache.put()
方法的具体详情如下:
包路径:net.sf.ehcache.Ehcache
类名称:Ehcache
方法名:put
[英]Put an element in the cache.
Resets the access statistics on the element, which would be the case if it has previously been gotten from a cache, and is now being put back.
Also notifies the CacheEventListener that:
代码示例来源:origin: spring-projects/spring-framework
@Override
public void put(Object key, @Nullable Object value) {
this.cache.put(new Element(key, value));
}
代码示例来源:origin: AxonFramework/AxonFramework
@Override
public <K, V> void put(K key, V value) {
ehCache.put(new Element(key, value));
}
代码示例来源:origin: apache/kylin
public void put(Object key, Object value) {
this.cache.put(new Element(key, value));
}
代码示例来源:origin: org.springframework/spring-context-support
@Override
public void put(Object key, @Nullable Object value) {
this.cache.put(new Element(key, value));
}
代码示例来源:origin: gocd/gocd
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));
}
代码示例来源:origin: spring-projects/spring-security
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);
}
代码示例来源:origin: gocd/gocd
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;
}
}
代码示例来源:origin: spring-projects/spring-security
public void putUserInCache(UserDetails user) {
Element element = new Element(user.getUsername(), user);
if (logger.isDebugEnabled()) {
logger.debug("Cache put: " + element.getKey());
}
cache.put(element);
}
代码示例来源:origin: org.springframework.security/spring-security-core
public void putUserInCache(UserDetails user) {
Element element = new Element(user.getUsername(), user);
if (logger.isDebugEnabled()) {
logger.debug("Cache put: " + element.getKey());
}
cache.put(element);
}
代码示例来源:origin: jooby-project/jooby
@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));
}
代码示例来源:origin: gocd/gocd
@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;
}
}
代码示例来源:origin: apache/shiro
/**
* 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);
}
}
代码示例来源:origin: spring-projects/spring-security
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));
}
代码示例来源:origin: spring-projects/spring-security
@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);
}
代码示例来源:origin: hibernate/hibernate-orm
@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 );
}
}
}
代码示例来源:origin: spring-projects/spring-security
@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);
}
代码示例来源:origin: spring-projects/spring-framework
@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));
}
代码示例来源:origin: net.sf.ehcache/ehcache
@Override
public Void put() {
underlyingCache.put(element, doNotNotifyCacheReplicators);
return null;
}
});
代码示例来源:origin: net.sf.ehcache/ehcache
@Override
public Void put() {
if (element.getObjectValue() != null) {
underlyingCache.put(element);
} else {
underlyingCache.remove(element.getObjectKey());
}
return null;
}
});
代码示例来源:origin: gravitee-io/gravitee-gateway
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));
}
}
内容来源于网络,如有侵权,请联系作者删除!