Java Code Examples for org.apache.cassandra.config.DatabaseDescriptor#getCounterCacheSizeInMB()

The following examples show how to use org.apache.cassandra.config.DatabaseDescriptor#getCounterCacheSizeInMB() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CacheService.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private AutoSavingCache<CounterCacheKey, ClockAndCount> initCounterCache()
{
    logger.info("Initializing counter cache with capacity of {} MBs", DatabaseDescriptor.getCounterCacheSizeInMB());

    long capacity = DatabaseDescriptor.getCounterCacheSizeInMB() * 1024 * 1024;

    AutoSavingCache<CounterCacheKey, ClockAndCount> cache =
        new AutoSavingCache<>(ConcurrentLinkedHashCache.<CounterCacheKey, ClockAndCount>create(capacity),
                              CacheType.COUNTER_CACHE,
                              new CounterCacheSerializer());

    int keysToSave = DatabaseDescriptor.getCounterCacheKeysToSave();

    logger.info("Scheduling counter cache save to every {} seconds (going to save {} keys).",
                DatabaseDescriptor.getCounterCacheSavePeriod(),
                keysToSave == Integer.MAX_VALUE ? "all" : keysToSave);

    cache.scheduleSaving(DatabaseDescriptor.getCounterCacheSavePeriod(), keysToSave);

    return cache;
}