Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
fengzhizi715 committed Feb 21, 2021
1 parent e8349ee commit 5c2faf4
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public class LFUCache<K, V> {
/* current size of Cache */
private int size;

public LFUCache(int capacity) {
public LFUCache(int capacity,CacheStatistics cacheStatistics) {
this.capacity = capacity;
size = 0;
kvStore = new HashMap<K, LFUCacheEntry<K, V>>();
freqList = new NodeList();
frequencyMap = new HashMap<Integer, FrequencyNode>();
cacheStatistics = new CacheStatistics(capacity);
this.size = 0;
this.kvStore = new HashMap<K, LFUCacheEntry<K, V>>();
this.freqList = new NodeList();
this.frequencyMap = new HashMap<Integer, FrequencyNode>();
this.cacheStatistics = cacheStatistics;
}

public boolean containsKey(K key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,12 @@ public class LRUCache<K,V> {
private CacheStatistics cacheStatistics;
private int size = 0;

public LRUCache() {

this(Constant.DEFAULT_CACHE_SIZE);
}

public LRUCache(int size) {
public LRUCache(int size,CacheStatistics cacheStatistics) {

this.size = size;
this.cache = new ConcurrentHashMap<K,V>(size);
this.queue = new ConcurrentLinkedQueue<K>();
this.cacheStatistics = new CacheStatistics(size);
this.cacheStatistics = cacheStatistics;
}

public boolean containsKey(K key) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.safframework.rxcache.memory.impl;

import com.safframework.rxcache.domain.CacheStatistics;
import com.safframework.rxcache.memory.Memory;

import java.util.HashMap;
Expand All @@ -12,6 +13,7 @@ public abstract class AbstractMemoryImpl implements Memory {

protected Map<String, Long> timestampMap;
protected Map<String, Long> expireTimeMap;
protected CacheStatistics cacheStatistics;

protected long maxSize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class FIFOMemoryImpl extends AbstractMemoryImpl {

private Map<String,Object> cache;
private List<String> keys;
private CacheStatistics cacheStatistics;

public FIFOMemoryImpl() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public LFUMemoryImpl() {
public LFUMemoryImpl(long maxSize) {

super(maxSize);
cache = new LFUCache<String, Object>((int) maxSize);
cache = new LFUCache<String, Object>((int) maxSize,new CacheStatistics((int)maxSize));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public LRUMemoryImpl() {
public LRUMemoryImpl(long maxSize) {

super(maxSize);
cache = new LRUCache<String,Object>((int)maxSize);
cache = new LRUCache<String,Object>((int)maxSize,new CacheStatistics((int)maxSize));
}

@Override
Expand Down

0 comments on commit 5c2faf4

Please sign in to comment.