net.sf.ehcache.Ehcache.put()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(289)

本文整理了Java中net.sf.ehcache.Ehcache.put()方法的一些代码示例,展示了Ehcache.put()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ehcache.put()方法的具体详情如下:
包路径:net.sf.ehcache.Ehcache
类名称:Ehcache
方法名:put

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:

  • the element was put, but only if the Element was actually put.
  • if the element exists in the cache, that an update has occurred, even if the element would be expired if it was requested
    [中]将元素放入缓存中。
    重置元素上的访问统计信息,如果该元素以前是从缓存中获取的,现在又被放回缓存中,则会出现这种情况。
    还通知CacheEventListener:
    *元素已放置,但仅当元素已实际放置时。
    *如果缓存中存在该元素,则表明已发生更新,即使请求该元素时该元素将过期

代码示例

代码示例来源:origin: spring-projects/spring-framework

  1. @Override
  2. public void put(Object key, @Nullable Object value) {
  3. this.cache.put(new Element(key, value));
  4. }

代码示例来源:origin: AxonFramework/AxonFramework

  1. @Override
  2. public <K, V> void put(K key, V value) {
  3. ehCache.put(new Element(key, value));
  4. }

代码示例来源:origin: apache/kylin

  1. public void put(Object key, Object value) {
  2. this.cache.put(new Element(key, value));
  3. }

代码示例来源:origin: org.springframework/spring-context-support

  1. @Override
  2. public void put(Object key, @Nullable Object value) {
  3. this.cache.put(new Element(key, value));
  4. }

代码示例来源:origin: gocd/gocd

  1. private void put(String key, Object value, Predicate predicate) {
  2. logUnsavedPersistentObjectInteraction(value, "PersistentObject {} added to cache without an id.");
  3. if (predicate.isTrue()) {
  4. LOGGER.debug("transaction active during cache put for {} = {}", key, value, new IllegalStateException());
  5. return;
  6. }
  7. ehCache.put(new Element(key, value));
  8. }

代码示例来源:origin: spring-projects/spring-security

  1. public void putTicketInCache(final CasAuthenticationToken token) {
  2. final Element element = new Element(token.getCredentials().toString(), token);
  3. if (logger.isDebugEnabled()) {
  4. logger.debug("Cache put: " + element.getKey());
  5. }
  6. cache.put(element);
  7. }

代码示例来源:origin: gocd/gocd

  1. public <T> T get(String key, Supplier<T> compute) {
  2. Element element = ehcache.get(key);
  3. if (element != null) {
  4. return (T) element.getObjectValue();
  5. }
  6. synchronized (key.intern()) {
  7. element = ehcache.get(key);
  8. if (element != null) {
  9. return (T) element.getObjectValue();
  10. }
  11. T object = compute.get();
  12. ehcache.put(new Element(key, object));
  13. return object;
  14. }
  15. }

代码示例来源:origin: spring-projects/spring-security

  1. public void putUserInCache(UserDetails user) {
  2. Element element = new Element(user.getUsername(), user);
  3. if (logger.isDebugEnabled()) {
  4. logger.debug("Cache put: " + element.getKey());
  5. }
  6. cache.put(element);
  7. }

代码示例来源:origin: org.springframework.security/spring-security-core

  1. public void putUserInCache(UserDetails user) {
  2. Element element = new Element(user.getUsername(), user);
  3. if (logger.isDebugEnabled()) {
  4. logger.debug("Cache put: " + element.getKey());
  5. }
  6. cache.put(element);
  7. }

代码示例来源:origin: jooby-project/jooby

  1. @Override
  2. public void save(final Session session) {
  3. Map<String, String> attributes = new HashMap<>(session.attributes());
  4. attributes.put("_accessedAt", Long.toString(session.accessedAt()));
  5. attributes.put("_createdAt", Long.toString(session.createdAt()));
  6. attributes.put("_savedAt", Long.toString(session.savedAt()));
  7. cache.put(new Element(session.id(), attributes));
  8. }

代码示例来源:origin: gocd/gocd

  1. @Override
  2. public Object extractPrincipal(X509Certificate cert) {
  3. try {
  4. Element element = cache.get(cert);
  5. if (element != null) {
  6. return element.getObjectValue();
  7. }
  8. } catch (CacheException cacheException) {
  9. throw new DataRetrievalFailureException("Cache failure: " + cacheException.getMessage());
  10. }
  11. final Object principal = delegate.extractPrincipal(cert);
  12. cache.put(new Element(cert, principal));
  13. return principal;
  14. }
  15. }

代码示例来源:origin: apache/shiro

  1. /**
  2. * Puts an object into the cache.
  3. *
  4. * @param key the key.
  5. * @param value the value.
  6. */
  7. public V put(K key, V value) throws CacheException {
  8. if (log.isTraceEnabled()) {
  9. log.trace("Putting object in cache [" + cache.getName() + "] for key [" + key + "]");
  10. }
  11. try {
  12. V previous = get(key);
  13. Element element = new Element(key, value);
  14. cache.put(element);
  15. return previous;
  16. } catch (Throwable t) {
  17. throw new CacheException(t);
  18. }
  19. }

代码示例来源:origin: spring-projects/spring-security

  1. public void putInCache(MutableAcl acl) {
  2. Assert.notNull(acl, "Acl required");
  3. Assert.notNull(acl.getObjectIdentity(), "ObjectIdentity required");
  4. Assert.notNull(acl.getId(), "ID required");
  5. if (this.aclAuthorizationStrategy == null) {
  6. if (acl instanceof AclImpl) {
  7. this.aclAuthorizationStrategy = (AclAuthorizationStrategy) FieldUtils
  8. .getProtectedFieldValue("aclAuthorizationStrategy", acl);
  9. this.permissionGrantingStrategy = (PermissionGrantingStrategy) FieldUtils
  10. .getProtectedFieldValue("permissionGrantingStrategy", acl);
  11. }
  12. }
  13. if ((acl.getParentAcl() != null) && (acl.getParentAcl() instanceof MutableAcl)) {
  14. putInCache((MutableAcl) acl.getParentAcl());
  15. }
  16. cache.put(new Element(acl.getObjectIdentity(), acl));
  17. cache.put(new Element(acl.getId(), acl));
  18. }

代码示例来源:origin: spring-projects/spring-security

  1. @Test
  2. public void putInCache() throws Exception {
  3. myCache.putInCache(acl);
  4. verify(cache, times(2)).put(element.capture());
  5. assertThat(element.getValue().getKey()).isEqualTo(acl.getId());
  6. assertThat(element.getValue().getObjectValue()).isEqualTo(acl);
  7. assertThat(element.getAllValues().get(0).getKey()).isEqualTo(
  8. acl.getObjectIdentity());
  9. assertThat(element.getAllValues().get(0).getObjectValue()).isEqualTo(acl);
  10. }

代码示例来源:origin: hibernate/hibernate-orm

  1. @Override
  2. public void putIntoCache(Object key, Object value, SharedSessionContractImplementor session) {
  3. try {
  4. final Element element = new Element( key, value );
  5. getCache().put( element );
  6. }
  7. catch (IllegalArgumentException | IllegalStateException e) {
  8. throw new CacheException( e );
  9. }
  10. catch (net.sf.ehcache.CacheException e) {
  11. if ( e instanceof NonStopCacheException ) {
  12. HibernateNonstopCacheExceptionHandler.getInstance()
  13. .handleNonstopCacheException( (NonStopCacheException) e );
  14. }
  15. else {
  16. throw new CacheException( e );
  17. }
  18. }
  19. }

代码示例来源:origin: spring-projects/spring-security

  1. @Test
  2. public void putInCacheAclWithParent() throws Exception {
  3. Authentication auth = new TestingAuthenticationToken("user", "password",
  4. "ROLE_GENERAL");
  5. auth.setAuthenticated(true);
  6. SecurityContextHolder.getContext().setAuthentication(auth);
  7. ObjectIdentity identityParent = new ObjectIdentityImpl(TARGET_CLASS,
  8. Long.valueOf(2));
  9. AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl(
  10. new SimpleGrantedAuthority("ROLE_OWNERSHIP"), new SimpleGrantedAuthority(
  11. "ROLE_AUDITING"), new SimpleGrantedAuthority("ROLE_GENERAL"));
  12. MutableAcl parentAcl = new AclImpl(identityParent, Long.valueOf(2),
  13. aclAuthorizationStrategy, new ConsoleAuditLogger());
  14. acl.setParent(parentAcl);
  15. myCache.putInCache(acl);
  16. verify(cache, times(4)).put(element.capture());
  17. List<Element> allValues = element.getAllValues();
  18. assertThat(allValues.get(0).getKey()).isEqualTo(parentAcl.getObjectIdentity());
  19. assertThat(allValues.get(0).getObjectValue()).isEqualTo(parentAcl);
  20. assertThat(allValues.get(1).getKey()).isEqualTo(parentAcl.getId());
  21. assertThat(allValues.get(1).getObjectValue()).isEqualTo(parentAcl);
  22. assertThat(allValues.get(2).getKey()).isEqualTo(acl.getObjectIdentity());
  23. assertThat(allValues.get(2).getObjectValue()).isEqualTo(acl);
  24. assertThat(allValues.get(3).getKey()).isEqualTo(acl.getId());
  25. assertThat(allValues.get(3).getObjectValue()).isEqualTo(acl);
  26. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void testExpiredElements() throws Exception {
  3. Assume.group(TestGroup.LONG_RUNNING);
  4. String key = "brancusi";
  5. String value = "constantin";
  6. Element brancusi = new Element(key, value);
  7. // ttl = 10s
  8. brancusi.setTimeToLive(3);
  9. nativeCache.put(brancusi);
  10. assertEquals(value, cache.get(key).get());
  11. // wait for the entry to expire
  12. Thread.sleep(5 * 1000);
  13. assertNull(cache.get(key));
  14. }

代码示例来源:origin: net.sf.ehcache/ehcache

  1. @Override
  2. public Void put() {
  3. underlyingCache.put(element, doNotNotifyCacheReplicators);
  4. return null;
  5. }
  6. });

代码示例来源:origin: net.sf.ehcache/ehcache

  1. @Override
  2. public Void put() {
  3. if (element.getObjectValue() != null) {
  4. underlyingCache.put(element);
  5. } else {
  6. underlyingCache.remove(element.getObjectKey());
  7. }
  8. return null;
  9. }
  10. });

代码示例来源:origin: gravitee-io/gravitee-gateway

  1. private void saveOrUpdate(ApiKey apiKey) {
  2. if (apiKey.isRevoked() || apiKey.isPaused()) {
  3. logger.debug("Remove a paused / revoked api-key from cache [key: {}] [plan: {}] [app: {}]", apiKey.getKey(), apiKey.getPlan(), apiKey.getApplication());
  4. cache.remove(apiKey.getKey());
  5. } else {
  6. logger.debug("Cache an api-key [key: {}] [plan: {}] [app: {}]", apiKey.getKey(), apiKey.getPlan(), apiKey.getApplication());
  7. cache.put(new Element(apiKey.getKey(), apiKey));
  8. }
  9. }

相关文章

Ehcache类方法