src/java/org/apache/cassandra/service/CacheService.java
/**
     * We can use Weighers.singleton() because Long can't be leaking memory
     * @return auto saving cache object
     */
We can use Weighers.singleton() because Long can't be leaking memory
@return auto saving cache object
We can use Weighers . singleton () because Long can ' t be leaking memory @return auto saving cache object
private AutoSavingCache<KeyCacheKey, Long> initKeyCache()
    {
        logger.info("Initializing key cache with capacity of {} MBs.", DatabaseDescriptor.getKeyCacheSizeInMB());
        int keyCacheInMemoryCapacity = DatabaseDescriptor.getKeyCacheSizeInMB() * 1024 * 1024;
        ICache<KeyCacheKey, Long> kc = ConcurrentLinkedHashCache.create(keyCacheInMemoryCapacity / AVERAGE_KEY_CACHE_ROW_SIZE);
        AutoSavingCache<KeyCacheKey, Long> keyCache = new AutoSavingCache<KeyCacheKey, Long>(kc, CacheType.KEY_CACHE);
        int keyCacheKeysToSave = DatabaseDescriptor.getKeyCacheKeysToSave();
        logger.info("Scheduling key cache save to each {} seconds (going to save {} keys).",
                    keyCacheSavePeriod,
                    keyCacheKeysToSave == Integer.MAX_VALUE ? "all" : keyCacheKeysToSave);
        keyCache.scheduleSaving(keyCacheSavePeriod, keyCacheKeysToSave);
        return keyCache;
    }
private AutoSavingCache < KeyCacheKey , Long > initKeyCache ( ) { logger . info ( "Initializing key cache with capacity of {} MBs." , DatabaseDescriptor . getKeyCacheSizeInMB ( ) ) ; int keyCacheInMemoryCapacity = DatabaseDescriptor . getKeyCacheSizeInMB ( ) * 1024 * 1024 ; ICache < KeyCacheKey , Long > kc = ConcurrentLinkedHashCache . create ( keyCacheInMemoryCapacity / AVERAGE_KEY_CACHE_ROW_SIZE ) ; AutoSavingCache < KeyCacheKey , Long > keyCache = new AutoSavingCache < KeyCacheKey , Long > ( kc , CacheType . KEY_CACHE ) ; int keyCacheKeysToSave = DatabaseDescriptor . getKeyCacheKeysToSave ( ) ; logger . info ( "Scheduling key cache save to each {} seconds (going to save {} keys)." , keyCacheSavePeriod , keyCacheKeysToSave == Integer . MAX_VALUE ? "all" : keyCacheKeysToSave ) ; keyCache . scheduleSaving ( keyCacheSavePeriod , keyCacheKeysToSave ) ; return keyCache ; }
We can use Weighers.singleton() because Long can't be leaking memory
 @return auto saving cache object
We can use Weighers . singleton () because Long can ' t be leaking memory @return auto saving cache object
// as values are constant size we can use singleton weigher // where 48 = 40 bytes (average size of the key) + 8 bytes (size of value)