Package org.springframework.cache.Cache

Examples of org.springframework.cache.Cache.ValueWrapper


      cache.evict("prodef-" + processDefine.getProcessDefName());
    }
  }
 
  private ProcessDefine getCacheValue(String key) {
    ValueWrapper wrapper = cache.get(key);
    if(wrapper != null)
      return (ProcessDefine)cache.get(key).get();
    else
      return null;
  }
View Full Code Here


    String stored = (String) client.get(key);
    assertNotNull(stored);
    assertEquals(value, stored);

    ValueWrapper loaded = cache.get(key);
    assertEquals(value, loaded.get());
  }
View Full Code Here

    Timer timer = new Timer(getCachedUri(request));
    timer.start();

    String key = calculateKey(request);
    PageInfo pageInfo;
    ValueWrapper element = cacheStatus.valueWrapper;
    log.debug("Serving cached content for {}", key);
    pageInfo = (PageInfo) element.get();

    for (Map.Entry<String, ? extends Serializable> entry : pageInfo.getRequestAttributes().entrySet()) {
      request.setAttribute(entry.getKey(), entry.getValue());
    }
View Full Code Here

    boolean trace = log.isTraceEnabled();
    boolean updateRequired = false;
    boolean atLeastOne = false;

    ValueWrapper valueWrapper = null;

    for (CacheOperationContext context : cacheables) {
      if (context.isConditionPassing()) {
        atLeastOne = true;
        Object key = context.generateKey();

        if (trace) {
          log.trace("Computed cache key {} for operation {}", new Object[] { key, context.operation });
        }
        if (key == null) {
          throw new IllegalArgumentException(
              "Null key returned for cache operation (maybe you are using named params on classes without debug info?) " +
              context.operation);
        }

        // add op/key (in case an update is discovered later on)
        cUpdates.put(context, key);

        boolean localCacheHit = false;

        // check whether the cache needs to be inspected or not (the method will be invoked anyway)
        if (!updateRequired) {
          for (Cache cache : context.getCaches()) {
            ValueWrapper wrapper = cache.get(key);
            if (wrapper != null) {
              valueWrapper = wrapper;
              localCacheHit = true;
              break;
            }
View Full Code Here

      response.getWriter().write(page);
    }
  }

  protected void update(Collection<Cache> caches, PageInfo pageInfo, CacheStatus cacheStatus, String key) {
    ValueWrapper element = cacheStatus == null ? null : cacheStatus.valueWrapper;
    Object maxAge = pageInfo.getCacheDirectives().get("max-age");
    int timeToLive = (maxAge instanceof Integer) ? ((Integer)maxAge) : (int)pageInfo.getTimeToLiveSeconds();
    for (Cache cache : caches) {
      log.debug("Response ok. Adding to cache {} with key {} and ttl {}",
          new Object[] { cache.getName(), key, getTimeToLive(element) });
View Full Code Here

        // Collect puts from any @Cachable miss
        List<CachePutRequest> cachePutRequests = new ArrayList<CachePutRequest>();
        collectPutRequests(contexts.get(CacheableOperation.class), ExpressionEvaluator.NO_RESULT, cachePutRequests, true);

        ValueWrapper result = null;

        Collection<CacheOperationContext> cacheOperationContexts = contexts.get(CacheableOperation.class);
        // We only attempt to get a cached result if there are has @Cachable
        if (!cacheOperationContexts.isEmpty()) {
            result = findCachedResult(cacheOperationContexts);
        }

        // Invoke the method if don't have a cache hit
        if (result == null) {
            result = new SimpleValueWrapper(invoker.invoke());
        }

        // Collect any explicit @CachePuts
        collectPutRequests(contexts.get(CachePutOperation.class), result.get(), cachePutRequests, false);

        // Process any collected put requests, either from @CachePut or a @Cacheable miss
        for (CachePutRequest cachePutRequest : cachePutRequests) {
            cachePutRequest.apply(result.get());
        }

        // Process any late evictions
        processCacheEvicts(contexts.get(CacheEvictOperation.class), false, result.get());

        return result.get();
    }
View Full Code Here

            }
        }
    }

    private Cache.ValueWrapper findCachedResult(Collection<CacheOperationContext> contexts) {
        ValueWrapper result = null;
        for (CacheOperationContext context : contexts) {
            if (isConditionPassing(context, ExpressionEvaluator.NO_RESULT)) {
                if (result == null) {
                    result = findInCaches(context, generateKey(context, ExpressionEvaluator.NO_RESULT));
                }
View Full Code Here

        return result;
    }

    private Cache.ValueWrapper findInAnyCaches(Collection<CacheOperationContext> contexts, Object key) {
        for (CacheOperationContext context : contexts) {
            ValueWrapper wrapper = findInCaches(context, key);
            if (wrapper != null) {
                return wrapper;
            }
        }
        return null;
View Full Code Here

   */
  public Map<String, RegionInfo> getAll() {
    Map<String, RegionInfo> regions = Maps.newHashMap();
    if (config.isClustered()) {
      for (Object eachKey : ((Ehcache) (cache.getNativeCache())).getKeysWithExpiryCheck()) {
        ValueWrapper valueWrapper = cache.get(eachKey);
        if (valueWrapper != null && valueWrapper.get() != null) {
          regions.put((String) eachKey, (RegionInfo) valueWrapper.get());
        }
      }
    }
    return regions;
  }
View Full Code Here

  public ArrayList<String> getAllVisibleRegionNames() {
    final ArrayList<String> regions = new ArrayList<String>();
    if (config.isClustered()) {
      for (Object eachKey : ((Ehcache) (cache.getNativeCache())).getKeysWithExpiryCheck()) {
        ValueWrapper valueWrapper = cache.get(eachKey);
        if (valueWrapper != null && valueWrapper.get() != null) {
          final RegionInfo region = TypeConvertUtils.cast(valueWrapper.get());
          if (region.isVisible()) {
            regions.add((String) eachKey);
          }
        }
      }
View Full Code Here

TOP

Related Classes of org.springframework.cache.Cache.ValueWrapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.