@Override public NearCacheStats getNearCacheStats() { checkAvailable(); return nearCacheStats; }
@Override public void destroy() { clear(); }
protected long getTotalStorageMemoryCost(K key, R record) { return getKeyStorageMemoryCost(key) + getRecordStorageMemoryCost(record); }
@Override public V tryPublishReserved(K key, V value, long reservationId, boolean deserialize) { checkAvailable(); return updateAndGetReserved(key, value, reservationId, deserialize); }
@Override public V get(K key) { checkAvailable(); record = getRecord(key); if (record != null) { if (record.getRecordState() != READ_PERMITTED) { invalidate(key); nearCacheStats.incrementMisses(); return null; if (isRecordExpired(record)) { invalidate(key); onExpire(key, record); return null; onRecordAccess(record); nearCacheStats.incrementHits(); value = recordToValue(record); onGet(key, value, record); return value; } else { onGetError(key, value, record, error); throw rethrow(error);
@Override public void put(K key, Data keyData, V value, Data valueData) { checkAvailable(); // if there is no eviction configured we return if the Near Cache is full and it's a new key // (we have to check the key, otherwise we might lose updates on existing keys) if (evictionDisabled && evictionChecker.isEvictionRequired() && !containsRecordKey(key)) { return; } R record = null; R oldRecord = null; try { record = createRecord((V) selectInMemoryFormatFriendlyValue(inMemoryFormat, value, valueData)); onRecordCreate(key, keyData, record); oldRecord = putRecord(key, record); if (oldRecord == null) { nearCacheStats.incrementOwnedEntryCount(); } onPut(key, value, record, oldRecord); } catch (Throwable error) { onPutError(key, value, record, oldRecord, error); throw rethrow(error); } }
@Override public void put(K key, Data keyData, V value) { checkAvailable(); // if there is no eviction configured we return if the Near Cache is full and it's a new key // (we have to check the key, otherwise we might lose updates on existing keys) if (evictionDisabled && evictionChecker.isEvictionRequired() && !containsRecordKey(key)) { return; } R record = null; R oldRecord = null; try { record = valueToRecord(value); onRecordCreate(key, keyData, record); oldRecord = putRecord(key, record); if (oldRecord == null) { nearCacheStats.incrementOwnedEntryCount(); } onPut(key, value, record, oldRecord); } catch (Throwable error) { onPutError(key, value, record, oldRecord, error); throw rethrow(error); } }
@Override public long tryReserveForUpdate(K key, Data keyData) { checkAvailable(); // if there is no eviction configured we return if the Near Cache is full and it's a new key // (we have to check the key, otherwise we might lose updates on existing keys) if (evictionDisabled && evictionChecker.isEvictionRequired() && !containsRecordKey(key)) { return NOT_RESERVED; } R reservedRecord = getOrCreateToReserve(key, keyData); long reservationId = nextReservationId(); if (reservedRecord.casRecordState(RESERVED, reservationId)) { return reservationId; } else { return NOT_RESERVED; } }
@Override public void initialize() { this.records = createNearCacheRecordMap(nearCacheConfig); EvictionConfig evictionConfig = nearCacheConfig.getEvictionConfig(); this.evictionChecker = createNearCacheEvictionChecker(evictionConfig, nearCacheConfig); if (!evictionDisabled) { this.evictionStrategy = SamplingEvictionStrategy.INSTANCE; this.evictionPolicyEvaluator = getEvictionPolicyEvaluator(evictionConfig, classLoader); } }
@Override public void destroy() { super.destroy(); if (nearCachePreloader != null) { nearCachePreloader.destroy(); } }
@Override public V get(K key) { checkAvailable(); record = getRecord(key); if (record != null) { if (record.getRecordState() != READ_PERMITTED) { invalidate(key); nearCacheStats.incrementMisses(); return null; if (isRecordExpired(record)) { invalidate(key); onExpire(key, record); return null; onRecordAccess(record); nearCacheStats.incrementHits(); value = recordToValue(record); onGet(key, value, record); return value; } else { onGetError(key, value, record, error); throw rethrow(error);
@Override public long tryReserveForUpdate(K key, Data keyData) { checkAvailable(); // if there is no eviction configured we return if the Near Cache is full and it's a new key // (we have to check the key, otherwise we might lose updates on existing keys) if (evictionDisabled && evictionChecker.isEvictionRequired() && !containsRecordKey(key)) { return NOT_RESERVED; } R reservedRecord = getOrCreateToReserve(key, keyData); long reservationId = nextReservationId(); if (reservedRecord.casRecordState(RESERVED, reservationId)) { return reservationId; } else { return NOT_RESERVED; } }
@Override public void initialize() { this.records = createNearCacheRecordMap(nearCacheConfig); EvictionConfig evictionConfig = nearCacheConfig.getEvictionConfig(); this.evictionChecker = createNearCacheEvictionChecker(evictionConfig, nearCacheConfig); if (!evictionDisabled) { this.evictionStrategy = SamplingEvictionStrategy.INSTANCE; this.evictionPolicyEvaluator = getEvictionPolicyEvaluator(evictionConfig, classLoader); } }
@Override public V tryPublishReserved(K key, V value, long reservationId, boolean deserialize) { checkAvailable(); return updateAndGetReserved(key, value, reservationId, deserialize); }
@Override public void destroy() { super.destroy(); if (nearCachePreloader != null) { nearCachePreloader.destroy(); } }
@Override public StaleReadDetector getStaleReadDetector() { checkAvailable(); return staleReadDetector; }
protected long getTotalStorageMemoryCost(K key, R record) { return getKeyStorageMemoryCost(key) + getRecordStorageMemoryCost(record); }
@Override public void destroy() { clear(); }
@Override public NearCacheStats getNearCacheStats() { checkAvailable(); return nearCacheStats; }
@Override public void doEviction(boolean withoutMaxSizeCheck) { checkAvailable(); if (!evictionDisabled) { EvictionChecker evictionChecker = withoutMaxSizeCheck ? null : this.evictionChecker; evictionStrategy.evict(records, evictionPolicyEvaluator, evictionChecker, this); } }