Example usage for org.springframework.cache Cache clear

List of usage examples for org.springframework.cache Cache clear

Introduction

In this page you can find the example usage for org.springframework.cache Cache clear.

Prototype

void clear();

Source Link

Document

Clear the cache through removing all mappings.

Usage

From source file:sample.cache.SampleCacheApplicationTests.java

@Test
public void validateCache() {
    Cache countries = this.cacheManager.getCache("countries");
    assertThat(countries, is(notNullValue()));
    countries.clear(); // Simple test assuming the cache is empty
    assertThat(countries.get("BE"), is(nullValue()));
    Country be = this.countryRepository.findByCode("BE");
    assertThat((Country) countries.get("BE").get(), is(be));
}

From source file:grails.plugin.cache.redis.GrailsRedisCacheManager.java

public boolean destroyCache(String name) {
    Cache cache = caches.remove(name);
    if (cache != null) {
        // TODO remove Redis backing store
        cache.clear();
    }/* w ww . j  a  v  a  2  s  .com*/

    return true;
}

From source file:com.couchbase.client.spring.cache.wiring.AbstractCouchbaseCacheWiringTest.java

@After
public void cleanCache() {
    Cache cache = cacheManager.getCache(CacheEnabledTestConfiguration.DATA_CACHE_NAME);
    cache.clear();
}

From source file:com.hp.autonomy.frontend.find.hod.search.FindHodDocumentService.java

@Override
protected Documents<HodSearchResult> queryTextIndex(final SearchRequest<ResourceIdentifier> searchRequest,
        final boolean fetchPromotions) throws HodErrorException {
    try {/*from w  w w  .ja v  a 2 s  .  c  o m*/
        return super.queryTextIndex(searchRequest, fetchPromotions);
    } catch (final HodErrorException e) {
        if (e.getErrorCode() == HodErrorCode.INDEX_NAME_INVALID) {
            final Boolean publicIndexesEnabled = findConfigService.getConfig().getIod()
                    .getPublicIndexesEnabled();
            final HodDatabasesRequest databasesRequest = new HodDatabasesRequest.Builder()
                    .setPublicIndexesEnabled(publicIndexesEnabled).build();

            final Cache cache = cacheManager.getCache(CacheNames.DATABASES);
            if (cache != null) {
                cache.clear();
            }
            final Set<Database> updatedDatabases = databasesService.getDatabases(databasesRequest);

            final QueryRestrictions<ResourceIdentifier> queryRestrictions = searchRequest
                    .getQueryRestrictions();
            final Set<ResourceIdentifier> badIndexes = new HashSet<>(queryRestrictions.getDatabases());

            for (final Database database : updatedDatabases) {
                final ResourceIdentifier resourceIdentifier = new ResourceIdentifier(database.getDomain(),
                        database.getName());
                badIndexes.remove(resourceIdentifier);
            }

            final List<ResourceIdentifier> goodIndexes = new ArrayList<>(queryRestrictions.getDatabases());
            goodIndexes.removeAll(badIndexes);

            searchRequest.setQueryRestrictions(new HodQueryRestrictions.Builder()
                    .setQueryText(queryRestrictions.getQueryText())
                    .setFieldText(queryRestrictions.getFieldText()).setDatabases(goodIndexes)
                    .setMinDate(queryRestrictions.getMinDate()).setMaxDate(queryRestrictions.getMaxDate())
                    .setMinScore(queryRestrictions.getMinScore())
                    .setStateMatchId(queryRestrictions.getStateMatchId())
                    .setStateDontMatchId(queryRestrictions.getStateDontMatchId()).build());
            final Documents<HodSearchResult> resultDocuments = super.queryTextIndex(searchRequest,
                    fetchPromotions);
            final Warnings warnings = new Warnings(badIndexes);
            return new Documents<>(resultDocuments.getDocuments(), resultDocuments.getTotalResults(),
                    resultDocuments.getExpandedQuery(), resultDocuments.getSuggestion(),
                    resultDocuments.getAutoCorrection(), warnings);
        } else {
            throw e;
        }
    }
}

From source file:net.eusashead.spring.gaecache.GaeCacheITCase.java

@Test
public void testEvictAll() throws Exception {

    // Create 2 caches
    Cache cache1 = cacheManager.getCache("cache1");
    Cache cache2 = cacheManager.getCache("cache2");

    // 2 objects for 2 caches
    Foo foo1 = new Foo(new FooKey(1l), "foo1");
    cache1.put(GaeCacheKey.create("foo1"), foo1);
    Foo foo2 = new Foo(new FooKey(2l), "foo2");
    cache2.put(GaeCacheKey.create("foo2"), foo2);

    // Are they cached?
    assertCached(ms, foo1, "cache1", "foo1");
    assertCached(ms, foo2, "cache2", "foo2");

    // Clear cache 2
    cache2.clear();

    // Make sure cache 1 is OK
    assertCached(ms, foo1, "cache1", "foo1");

    // Make sure the cleared cache is clear
    assertNotCached(ms, "cache2", "foo2");

}

From source file:grails.plugin.cache.web.filter.PageFragmentCachingFilter.java

protected boolean inspectCacheEvicts(Collection<CacheOperationContext> evictions, boolean beforeInvocation) {
    if (evictions.isEmpty()) {
        return false;
    }/*  w ww. ja v a  2s.  c  o  m*/

    boolean trace = log.isTraceEnabled();

    boolean atLeastOne = false;
    for (CacheOperationContext operationContext : evictions) {
        CacheEvictOperation evict = (CacheEvictOperation) operationContext.operation;

        if (beforeInvocation == evict.isBeforeInvocation()) {
            if (operationContext.isConditionPassing()) {
                atLeastOne = true;
                // for each cache
                // lazy key initialization
                Object key = null;

                for (Cache cache : operationContext.getCaches()) {
                    // cache-wide flush
                    if (evict.isCacheWide()) {
                        cache.clear();
                        logRequestDetails(operationContext.request, getContext(), "Flushing request");
                    } else {
                        // check key
                        if (key == null) {
                            key = operationContext.generateKey();
                        }
                        if (trace) {
                            log.trace("Invalidating cache key {} for operation {} on method {}",
                                    new Object[] { key, evict, operationContext.method });
                        }
                        cache.evict(key);
                    }
                }
            } else {
                logRequestDetails(operationContext.request, getContext(), "Not flushing request");
            }
        }
    }
    return atLeastOne;
}

From source file:org.entando.entando.aps.system.services.cache.CacheInfoManager.java

public void flushAll(String cacheName) {
    Cache cache = this.getCache(cacheName);
    cache.clear();
    Map<String, List<String>> objectsByGroup = this._cachesObjectGroups.get(cacheName);
    if (null != objectsByGroup) {
        objectsByGroup.clear();/*from  w  w  w .  ja v a2  s  . com*/
    }
}

From source file:org.kuali.rice.core.impl.cache.CacheAdminServiceImpl.java

@Override
public void flush(Collection<CacheTarget> cacheTargets) throws RiceIllegalArgumentException {
    if (CollectionUtils.isNotEmpty(cacheTargets)) {
        logCacheFlush(cacheTargets);//  w  w w . j  a va 2 s. com
        for (CacheTarget cacheTarget : cacheTargets) {
            if (cacheTarget == null) {
                throw new RiceIllegalArgumentException("cacheTarget is null");
            }
            final Cache c = getCache(cacheTarget.getCache());
            if (c != null) {
                if (cacheTarget.containsKey()) {
                    c.evict(cacheTarget.getKey());
                } else {
                    c.clear();
                }
            }
        }
    }
}

From source file:org.kuali.rice.kew.rule.service.impl.RuleServiceInternalImpl.java

private void clearCache(String cacheName) {
    DistributedCacheManagerDecorator distributedCacheManagerDecorator = GlobalResourceLoader
            .getService(KewImplConstants.KEW_DISTRIBUTED_CACHE_MANAGER);

    Cache cache = distributedCacheManagerDecorator.getCache(cacheName);
    if (cache != null) {
        cache.clear();
    }//from ww w .j  a  va2s  .c  om
}

From source file:org.opentestsystem.delivery.testreg.service.impl.TestRegUberEntityRelationshipServiceImpl.java

private void loadInstitutionNcesIdCache() {
    // invalidate cache
    final Cache ncesidCache = this.cacheManager.getCache("institution.ncesid");

    if (ncesidCache != null) {
        ncesidCache.clear();
    }//from   w w  w  .  ja  va  2 s . c o m

    final List<String> ncesids = this.institutionRepository.findAllNcesIds();
    final HashSet<String> ncesIdSet = new HashSet<String>(ncesids);
    ncesidCache.put("ncesids", ncesIdSet);
}