Example usage for com.google.common.cache LoadingCache invalidateAll

List of usage examples for com.google.common.cache LoadingCache invalidateAll

Introduction

In this page you can find the example usage for com.google.common.cache LoadingCache invalidateAll.

Prototype

void invalidateAll();

Source Link

Document

Discards all entries in the cache.

Usage

From source file:org.gitools.matrix.model.mtabixmatrix.MTabixMatrix.java

public void detach() {

    //TODO improve evict policy
    for (LoadingCache<Long, MTabixBlockValues> cache : indexedCache.values()) {
        cache.invalidateAll();
    }//from  w ww.  ja v a2 s . co  m

}

From source file:org.jasig.portal.portlet.container.cache.PrivatePortletCacheKeyTracker.java

@Override
public void notifyRemoveAll(Ehcache cache) {
    for (final LoadingCache<IPortletWindowId, Set<PrivatePortletCacheKey>> privatePortletCacheKeys : this.privatePortletCacheKeysBySession
            .values()) {//from w w  w. j  av  a2  s.  c o m
        privatePortletCacheKeys.invalidateAll();
    }
    this.privatePortletCacheKeysBySession.clear();

    logger.debug("Removed all cache keys tracker {}", this.sessionKey);
}

From source file:org.apereo.portal.utils.cache.TagTrackingCacheEventListener.java

@Override
public void notifyRemoveAll(Ehcache cache) {
    final String cacheName = cache.getName();
    final LoadingCache<CacheEntryTag, Set<Object>> cacheKeys = taggedCacheKeys.getIfPresent(cacheName);
    if (cacheKeys != null) {
        logger.debug("Tracking remove all tagged keys for cache {}", new Object[] { cacheName });
        cacheKeys.invalidateAll();
    }/*from w w w . j a va  2  s . c om*/
}

From source file:me.lucko.luckperms.sponge.service.LuckPermsService.java

public void invalidateOptionCaches() {
    for (LoadingCache<OptionLookup, Optional<String>> c : localOptionCaches) {
        c.invalidateAll();
    }//w  w w .j a va  2  s.co m

    for (User user : plugin.getUserManager().getAll().values()) {
        UserCache userCache = user.getUserData();
        if (userCache == null)
            continue;

        userCache.invalidateCache();
    }
}

From source file:me.lucko.luckperms.sponge.service.LuckPermsService.java

public void invalidateParentCaches() {
    for (LoadingCache<ImmutableContextSet, Set<SubjectReference>> c : localParentCaches) {
        c.invalidateAll();
    }//from  w w w  .  ja v  a 2  s  . c o m
    invalidateOptionCaches();
    invalidatePermissionCaches();
}

From source file:me.lucko.luckperms.sponge.service.LuckPermsService.java

public void invalidatePermissionCaches() {
    for (LoadingCache<PermissionLookup, Tristate> c : localPermissionCaches) {
        c.invalidateAll();
    }/*from w  w  w  .j a  va 2 s. co  m*/
    for (CalculatedSubjectData subjectData : localDataCaches) {
        subjectData.invalidateLookupCache();
    }

    plugin.getCalculatorFactory().invalidateAll();

    for (User user : plugin.getUserManager().getAll().values()) {
        UserCache userCache = user.getUserData();
        if (userCache == null)
            continue;

        userCache.invalidateCache();
    }

    for (SpongeGroup group : plugin.getGroupManager().getAll().values()) {
        group.getSpongeData().invalidateCaches();
    }
}

From source file:com.comcast.cdn.traffic_control.traffic_router.core.dns.ZoneManager.java

protected static void initZoneCache(final TrafficRouter tr) {
    synchronized (ZoneManager.class) {
        final CacheRegister cacheRegister = tr.getCacheRegister();
        final JSONObject config = cacheRegister.getConfig();

        int poolSize = 1;
        final double scale = config.optDouble("zonemanager.threadpool.scale", 0.75);
        final int cores = Runtime.getRuntime().availableProcessors();

        if (cores > 2) {
            final Double s = Math.floor((double) cores * scale);

            if (s.intValue() > 1) {
                poolSize = s.intValue();
            }/*  w  w  w. j ava2  s  .  c  om*/
        }

        final ExecutorService initExecutor = Executors.newFixedThreadPool(poolSize);

        final ExecutorService ze = Executors.newFixedThreadPool(poolSize);
        final ScheduledExecutorService me = Executors.newScheduledThreadPool(2); // 2 threads, one for static, one for dynamic, threads to refresh zones
        final int maintenanceInterval = config.optInt("zonemanager.cache.maintenance.interval", 300); // default 5 minutes
        final String dspec = "expireAfterAccess="
                + config.optString("zonemanager.dynamic.response.expiration", "300s"); // default to 5 minutes

        final LoadingCache<ZoneKey, Zone> dzc = createZoneCache(ZoneCacheType.DYNAMIC,
                CacheBuilderSpec.parse(dspec));
        final LoadingCache<ZoneKey, Zone> zc = createZoneCache(ZoneCacheType.STATIC);

        initZoneDirectory();

        try {
            LOGGER.info("Generating zone data");
            generateZones(tr, zc, dzc, initExecutor);
            initExecutor.shutdown();
            initExecutor.awaitTermination(5, TimeUnit.MINUTES);
            LOGGER.info("Zone generation complete");
        } catch (final InterruptedException ex) {
            LOGGER.warn("Initialization of zone data exceeded time limit of 5 minutes; continuing", ex);
        } catch (IOException ex) {
            LOGGER.fatal("Caught fatal exception while generating zone data!", ex);
        }

        me.scheduleWithFixedDelay(getMaintenanceRunnable(dzc, ZoneCacheType.DYNAMIC, maintenanceInterval), 0,
                maintenanceInterval, TimeUnit.SECONDS);
        me.scheduleWithFixedDelay(getMaintenanceRunnable(zc, ZoneCacheType.STATIC, maintenanceInterval), 0,
                maintenanceInterval, TimeUnit.SECONDS);

        final ExecutorService tze = ZoneManager.zoneExecutor;
        final ScheduledExecutorService tme = ZoneManager.zoneMaintenanceExecutor;
        final LoadingCache<ZoneKey, Zone> tzc = ZoneManager.zoneCache;
        final LoadingCache<ZoneKey, Zone> tdzc = ZoneManager.dynamicZoneCache;

        ZoneManager.zoneExecutor = ze;
        ZoneManager.zoneMaintenanceExecutor = me;
        ZoneManager.dynamicZoneCache = dzc;
        ZoneManager.zoneCache = zc;

        if (tze != null) {
            tze.shutdownNow();
        }

        if (tme != null) {
            tme.shutdownNow();
        }

        if (tzc != null) {
            tzc.invalidateAll();
        }

        if (tdzc != null) {
            tdzc.invalidateAll();
        }
    }
}

From source file:com.android.builder.shrinker.JavaSerializationShrinkerGraph.java

@SuppressWarnings("unchecked") // readObject() returns an Object, we need to cast it.
@Override//from www.  j ava2 s.co m
public void loadState() throws IOException {
    ObjectInputStream stream = new ObjectInputStream(
            new BufferedInputStream(new FileInputStream(getStateFile())));

    try {
        mClasses = (ConcurrentMap<String, ClassInfo>) stream.readObject();
        mMembers = (SetMultimap<String, String>) stream.readObject();
        mDependencies = (SetMultimap<String, Dependency<String>>) stream.readObject();
        Map<ShrinkType, Map<String, Counter>> countersMap = (Map<ShrinkType, Map<String, Counter>>) stream
                .readObject();

        for (Map.Entry<ShrinkType, Map<String, Counter>> entry : countersMap.entrySet()) {
            LoadingCache<String, Counter> cache = mReferenceCounters.get(entry.getKey());
            cache.invalidateAll();
            cache.putAll(entry.getValue());
        }
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    } finally {
        stream.close();
    }
}

From source file:org.apache.brooklyn.location.basic.SshMachineLocation.java

protected <T> T execSsh(final Map<String, ?> props, final Function<ShellTool, T> task) {
    final LoadingCache<Map<String, ?>, Pool<SshTool>> sshPoolCache = getSshPoolCache();
    Pool<SshTool> pool = sshPoolCache.getUnchecked(props);
    if (LOG.isTraceEnabled()) {
        LOG.trace("{} execSsh got pool: {}", this, pool);
    }//  w w w .  j ava  2  s. c  om

    if (truth(props.get(CLOSE_CONNECTION.getName()))) {
        Function<SshTool, T> close = new Function<SshTool, T>() {
            @Override
            public T apply(SshTool input) {
                T result = task.apply(input);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("{} invalidating all sshPoolCache entries: {}", SshMachineLocation.this,
                            sshPoolCache.stats().toString());
                }
                sshPoolCache.invalidateAll();
                sshPoolCache.cleanUp();
                return result;
            }
        };
        return pool.exec(close);
    } else {
        return pool.exec(task);
    }
}