com.neko233.toolchain.common.cache.objects.AbstractCache Maven / Gradle / Ivy
package com.neko233.toolchain.common.cache.objects;
import com.neko233.toolchain.common.cache.objects.metrics.CacheMetrics;
import com.neko233.toolchain.common.cache.objects.metrics.SimpleCacheMetrics;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
/**
* @author SolarisNeko on 2022-12-14
**/
public abstract class AbstractCache implements Cache, CacheMetrics {
protected CacheMetrics cacheMetrics = new SimpleCacheMetrics();
/**
* ----------------------- Cache Metrics ------------------------
*/
@Override
public CacheMetrics addHitCount(long count) {
return cacheMetrics.addHitCount(count);
}
@Override
public long getHitCount() {
return cacheMetrics.getHitCount();
}
@Override
public CacheMetrics addMissCount(long count) {
return cacheMetrics.addMissCount(count);
}
@Override
public long getMissCount() {
return cacheMetrics.getMissCount();
}
@Override
public CacheMetrics addEvictionCount(long count) {
return cacheMetrics.addEvictionCount(count);
}
@Override
public Long getEvictionCount() {
return cacheMetrics.getEvictionCount();
}
/**
* ----------------------- Cache ------------------------
*/
@Override
public boolean isNeedRefresh() {
throw new UnsupportedOperationException();
}
@Override
public void refresh() {
throw new UnsupportedOperationException();
}
@Override
public Cache put(K key, V value) {
throw new UnsupportedOperationException();
}
@Override
public Cache putAll(Map extends K, ? extends V> map) {
for (Map.Entry extends K, ? extends V> entry : map.entrySet()) {
put(entry.getKey(), entry.getValue());
}
return this;
}
@Override
public Cache isNeedFlush(boolean isNeedFlush) {
return null;
}
@Override
public Cache invalidate(K key) {
throw new UnsupportedOperationException();
}
@Override
public Cache invalidateAll(Iterable keys) {
for (K key : keys) {
invalidate(key);
}
return this;
}
@Override
public Cache invalidateAll() {
throw new UnsupportedOperationException();
}
@Override
public V get(K key) {
throw new UnsupportedOperationException();
}
@Override
public ConcurrentMap getAll() {
throw new UnsupportedOperationException();
}
@Override
public void cleanUp() {
throw new UnsupportedOperationException();
}
@Override
public V getOrCreate(K key, Supplier supplier) {
throw new UnsupportedOperationException();
}
@Override
public V getOrCreate(K key, V newValue) {
return Cache.super.getOrCreate(key, newValue);
}
@Override
public boolean isNeedFlush() {
throw new UnsupportedOperationException();
}
@Override
public void flushCallable(ConcurrentMap snapshot) {
throw new UnsupportedOperationException();
}
@Override
public Cache isNeedRefresh(boolean value) {
throw new UnsupportedOperationException();
}
@Override
public Cache addFlushListener(FlushListener listener) {
throw new UnsupportedOperationException();
}
@Override
public Cache removeFlushListener(FlushListener listener) {
throw new UnsupportedOperationException();
}
@Override
public Cache invalidateTime(int invalidateTime, TimeUnit timeUnit) {
throw new UnsupportedOperationException();
}
@Override
public Cache invalidateMaxSize(int maxSize) {
throw new UnsupportedOperationException();
}
}