16 #ifndef HAZELCAST_CLIENT_CONFIG_NEARCACHECONFIG_H_
17 #define HAZELCAST_CLIENT_CONFIG_NEARCACHECONFIG_H_
23 #include <boost/shared_ptr.hpp>
25 #include "hazelcast/client/config/InMemoryFormat.h"
26 #include "hazelcast/client/config/EvictionConfig.h"
27 #include "hazelcast/client/config/NearCacheConfigBase.h"
28 #include "hazelcast/client/serialization/pimpl/Data.h"
29 #include "hazelcast/client/TypedData.h"
31 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
33 #pragma warning(disable: 4251) //for dll export
43 template <
typename K,
typename V>
76 NearCacheConfig() : name(
"default"), timeToLiveSeconds(DEFAULT_TTL_SECONDS),
77 maxIdleSeconds(DEFAULT_MAX_IDLE_SECONDS),
78 inMemoryFormat(DEFAULT_MEMORY_FORMAT),
79 localUpdatePolicy(
INVALIDATE), invalidateOnChange(true), cacheLocalEntries(false),
83 NearCacheConfig(
const char *cacheName) : name(cacheName), timeToLiveSeconds(DEFAULT_TTL_SECONDS),
84 maxIdleSeconds(DEFAULT_MAX_IDLE_SECONDS),
85 inMemoryFormat(DEFAULT_MEMORY_FORMAT),
86 localUpdatePolicy(
INVALIDATE), invalidateOnChange(true),
87 cacheLocalEntries(false),
88 evictionConfig(new EvictionConfig<K, V>()) {
91 NearCacheConfig(
const char *cacheName, InMemoryFormat memoryFormat) : name(cacheName), timeToLiveSeconds(DEFAULT_TTL_SECONDS),
92 maxIdleSeconds(DEFAULT_MAX_IDLE_SECONDS),
93 inMemoryFormat(memoryFormat),
94 localUpdatePolicy(
INVALIDATE), invalidateOnChange(true),
95 cacheLocalEntries(false),
96 evictionConfig(new EvictionConfig<K, V>()) {
99 NearCacheConfig(int32_t timeToLiveSeconds, int32_t maxIdleSeconds,
bool invalidateOnChange,
100 InMemoryFormat inMemoryFormat, boost::shared_ptr<EvictionConfig<K, V> > evictConfig)
101 : evictionConfig(new EvictionConfig<K, V>()) {
102 this->timeToLiveSeconds = timeToLiveSeconds;
103 this->maxIdleSeconds = maxIdleSeconds;
104 this->invalidateOnChange = invalidateOnChange;
105 this->inMemoryFormat = inMemoryFormat;
108 if (evictConfig.get() != NULL) {
109 this->evictionConfig = evictConfig;
111 this->cacheLocalEntries =
false;
114 NearCacheConfig(
const NearCacheConfig<K, V> &config) {
115 name = config.getName();
116 inMemoryFormat = config.getInMemoryFormat();
117 invalidateOnChange = config.isInvalidateOnChange();
118 maxIdleSeconds = config.getMaxIdleSeconds();
119 timeToLiveSeconds = config.getTimeToLiveSeconds();
120 cacheLocalEntries = config.isCacheLocalEntries();
121 localUpdatePolicy = config.localUpdatePolicy;
123 if (config.evictionConfig.get() != NULL) {
124 this->evictionConfig = config.evictionConfig;
128 virtual ~NearCacheConfig() {
158 return timeToLiveSeconds;
170 this->timeToLiveSeconds = util::Preconditions::checkNotNegative(timeToLiveSeconds,
171 "TTL seconds cannot be negative!");
184 return maxIdleSeconds;
198 this->maxIdleSeconds = util::Preconditions::checkNotNegative(maxIdleSeconds,
199 "Max-Idle seconds cannot be negative!");
212 return invalidateOnChange;
226 this->invalidateOnChange = invalidateOnChange;
239 return inMemoryFormat;
252 this->inMemoryFormat = inMemoryFormat;
263 return cacheLocalEntries;
274 this->cacheLocalEntries = cacheLocalEntries;
279 return localUpdatePolicy;
282 NearCacheConfig &setLocalUpdatePolicy(
const LocalUpdatePolicy &localUpdatePolicy) {
283 this->localUpdatePolicy = localUpdatePolicy;
293 return evictionConfig;
303 this->evictionConfig = util::Preconditions::checkNotNull<EvictionConfig<K, V> >(evictionConfig,
304 "EvictionConfig cannot be NULL!");
308 std::ostream &operator<<(std::ostream &out) {
309 out <<
"NearCacheConfig{"
310 <<
"timeToLiveSeconds=" << timeToLiveSeconds
311 <<
", maxIdleSeconds=" << maxIdleSeconds
312 <<
", invalidateOnChange=" << invalidateOnChange
313 <<
", inMemoryFormat=" << inMemoryFormat
314 <<
", cacheLocalEntries=" << cacheLocalEntries
315 <<
", localUpdatePolicy=" << localUpdatePolicy
324 int32_t timeToLiveSeconds;
325 int32_t maxIdleSeconds;
327 InMemoryFormat inMemoryFormat;
331 bool invalidateOnChange;
332 bool cacheLocalEntries;
342 boost::shared_ptr<EvictionConfig<K, V> > evictionConfig;
344 int32_t calculateMaxSize(int32_t maxSize) {
345 return (maxSize == 0) ? INT32_MAX : util::Preconditions::checkNotNegative(maxSize,
346 "Max-size cannot be negative!");
350 template<
typename K,
typename V>
351 const int32_t NearCacheConfig<K, V>::DEFAULT_TTL_SECONDS = 0;
353 template<
typename K,
typename V>
354 const int32_t NearCacheConfig<K, V>::DEFAULT_MAX_IDLE_SECONDS = 0;
356 template<
typename K,
typename V>
357 const InMemoryFormat NearCacheConfig<K, V>::DEFAULT_MEMORY_FORMAT = BINARY;
361 namespace mixedtype {
369 virtual MixedNearCacheConfig &setInMemoryFormat(
const client::config::InMemoryFormat &inMemoryFormat) {
370 if (client::config::OBJECT == inMemoryFormat) {
371 throw exception::IllegalArgumentException(
372 "MixedNearCacheConfig does not allow setting the in memory format different from BINARY.");
384 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
bool isInvalidateOnChange() const
True to evict the cached entries if the entries are changed (updated or removed). ...
Definition: NearCacheConfig.h:211
Configuration for eviction.
Definition: EvictionConfig.h:43
bool isCacheLocalEntries() const
If true, cache local entries also.
Definition: NearCacheConfig.h:262
NearCacheConfig & setInvalidateOnChange(bool invalidateOnChange)
True to evict the cached entries if the entries are changed (updated or removed). ...
Definition: NearCacheConfig.h:225
static const InMemoryFormat DEFAULT_MEMORY_FORMAT
Default value for the in-memory format.
Definition: NearCacheConfig.h:59
This is a marker class to indicate that the derived class is a near cache config. ...
Definition: NearCacheConfigBase.h:32
Contains the configuration for a Near Cache.
Definition: NearCacheConfig.h:44
Definition: NearCacheConfig.h:363
NearCacheConfig & setMaxIdleSeconds(int32_t maxIdleSeconds)
Maximum number of seconds each entry can stay in the Near Cache as untouched (not-read).
Definition: NearCacheConfig.h:197
LocalUpdatePolicy
Local Update Policy enum.
Definition: NearCacheConfig.h:64
int32_t getMaxIdleSeconds() const
Maximum number of seconds each entry can stay in the Near Cache as untouched (not-read).
Definition: NearCacheConfig.h:183
INVALIDATE POLICY.
Definition: NearCacheConfig.h:68
const std::string & getName() const
Gets the name of the Near Cache.
Definition: NearCacheConfig.h:136
static const int32_t DEFAULT_MAX_IDLE_SECONDS
Default value of the idle time for eviction in seconds.
Definition: NearCacheConfig.h:54
NearCacheConfig & setEvictionConfig(const boost::shared_ptr< EvictionConfig< K, V > > &evictionConfig)
Sets the eviction configuration.
Definition: NearCacheConfig.h:302
NearCacheConfig & setCacheLocalEntries(bool cacheLocalEntries)
True to cache local entries also.
Definition: NearCacheConfig.h:273
virtual NearCacheConfig & setInMemoryFormat(const InMemoryFormat &inMemoryFormat)
Sets the data type used to store entries.
Definition: NearCacheConfig.h:251
NearCacheConfig & setName(const std::string &name)
Sets the name of the Near Cache.
Definition: NearCacheConfig.h:146
int32_t getTimeToLiveSeconds() const
Gets the maximum number of seconds for each entry to stay in the Near Cache.
Definition: NearCacheConfig.h:157
CACHE ON UPDATE POLICY.
Definition: NearCacheConfig.h:73
Definition: MapEntryView.h:32
static const int32_t DEFAULT_TTL_SECONDS
Default value of the time to live in seconds.
Definition: NearCacheConfig.h:49
const InMemoryFormat & getInMemoryFormat() const
Gets the data type used to store entries.
Definition: NearCacheConfig.h:238
NearCacheConfig & setTimeToLiveSeconds(int32_t timeToLiveSeconds)
Sets the maximum number of seconds for each entry to stay in the Near Cache.
Definition: NearCacheConfig.h:169
const boost::shared_ptr< EvictionConfig< K, V > > & getEvictionConfig() const
The eviction configuration.
Definition: NearCacheConfig.h:292