com.datatorrent.lib.db.cache.CacheStore Maven / Gradle / Ivy
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.datatorrent.lib.db.cache;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Lists;
/**
* A {@link CacheManager.Primary} which keeps key/value pairs in memory.
*
* Properties of the cache store:
*
* - Transient: It is not checkpointed.
* - Max Cache Size: it starts evicting entries before this limit is exceeded.
* - Entry expiry time: the entries epire after the specified duration.
* - Cache cleanup interval: the interval at which the cache is cleaned up of expired entries periodically.
*
*
* @since 0.9.2
*/
public class CacheStore implements CacheManager.Primary
{
@Min(0)
protected long maxCacheSize = 2000;
@Min(0)
protected int entryExpiryDurationInMillis = 60000; //1 minute
@Min(0)
protected int cacheCleanupIntervalInMillis = 60500; //.5 seconds after entries are expired
@NotNull
protected ExpiryType entryExpiryStrategy = ExpiryType.EXPIRE_AFTER_ACCESS;
private transient ScheduledExecutorService cleanupScheduler;
private transient Cache
© 2015 - 2025 Weber Informatics LLC | Privacy Policy