public int get(int key) { CacheItem<Integer, Integer> itm = cacheMap.get(key); if (itm == null) return -1; cacheList.delete(itm); cacheList.insertTail(itm); return itm.value.intValue(); }
private void updateItem(int key, int value) { CacheItem<Integer, Integer> exitedKey = cacheMap.get(key); exitedKey.value = value; cacheList.delete(exitedKey); cacheList.insertTail(exitedKey); }
private void addItem(int key, int value) { CacheItem<Integer, Integer> newCacheItem = new CacheItem<Integer, Integer>(key, value); cacheList.insertTail(newCacheItem); cacheMap.put(key, newCacheItem); cacheSize++; }