@SuppressWarnings("unchecked") public <K, V> Cache<K, V> createCache(String name) { int capacity = getCapacity(Preconditions.checkNotNull(name)); Cache<K, V> cache = (Cache<K, V>) caches.get(name); if (cache == null) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Creating cache named " + name); } cache = new LruCache<K, V>(capacity); caches.put(name, cache); } return cache; } }
@Override protected synchronized boolean removeEldestEntry(Map.Entry<K, V> eldest) { return size() > capacity; } }
@Test public void exceededCapacityRemoved() { for (int i = 0; i < TEST_CAPACITY + 1; ++i) { cache.addElement(Integer.toString(i), Integer.toString(i)); } assertEquals(TEST_CAPACITY, cache.size()); assertEquals(TEST_CAPACITY, cache.getSize()); assertEquals(TEST_CAPACITY, cache.getCapacity()); assertNull(cache.getElement("0")); } }
@Test public void normalCapacityOk() { for (int i = 0; i < TEST_CAPACITY; ++i) { cache.addElement(Integer.toString(i), Integer.toString(i)); } assertEquals(TEST_CAPACITY, cache.size()); assertEquals(TEST_CAPACITY, cache.getSize()); assertEquals(TEST_CAPACITY, cache.getCapacity()); assertEquals("0", cache.getElement("0")); }
@Test public void exceededCapacityRemoved() { for (int i = 0; i < TEST_CAPACITY + 1; ++i) { cache.addElement(Integer.toString(i), Integer.toString(i)); } assertEquals(TEST_CAPACITY, cache.size()); assertEquals(TEST_CAPACITY, cache.getSize()); assertEquals(TEST_CAPACITY, cache.getCapacity()); assertNull(cache.getElement("0")); } }
@SuppressWarnings("unchecked") public <K, V> Cache<K, V> createCache(String name) { int capacity = getCapacity(Preconditions.checkNotNull(name)); Cache<K, V> cache = (Cache<K, V>) caches.get(name); if (cache == null) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Creating cache named " + name); } cache = new LruCache<K, V>(capacity); caches.put(name, cache); } return cache; } }
@Override protected synchronized boolean removeEldestEntry(Map.Entry<K, V> eldest) { return size() > capacity; } }
@Test public void exceededCapacityRemoved() { for (int i = 0; i < TEST_CAPACITY + 1; ++i) { cache.addElement(Integer.toString(i), Integer.toString(i)); } assertEquals(TEST_CAPACITY, cache.size()); assertEquals(TEST_CAPACITY, cache.getSize()); assertEquals(TEST_CAPACITY, cache.getCapacity()); assertNull(cache.getElement("0")); } }
@SuppressWarnings("unchecked") public <K, V> Cache<K, V> createCache(String name) { int capacity = getCapacity(Preconditions.checkNotNull(name)); Cache<K, V> cache = (Cache<K, V>) caches.get(name); if (cache == null) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Creating cache named " + name); } cache = new LruCache<K, V>(capacity); caches.put(name, cache); } return cache; } }
@Override protected synchronized boolean removeEldestEntry(Map.Entry<K, V> eldest) { return size() > capacity; } }
@Test public void normalCapacityOk() { for (int i = 0; i < TEST_CAPACITY; ++i) { cache.addElement(Integer.toString(i), Integer.toString(i)); } assertEquals(TEST_CAPACITY, cache.size()); assertEquals(TEST_CAPACITY, cache.getSize()); assertEquals(TEST_CAPACITY, cache.getCapacity()); assertEquals("0", cache.getElement("0")); }
@SuppressWarnings("unchecked") public <K, V> Cache<K, V> createCache(String name) { int capacity = getCapacity(Preconditions.checkNotNull(name)); Cache<K, V> cache = (Cache<K, V>) caches.get(name); if (cache == null) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Creating cache named " + name); } cache = new LruCache<K, V>(capacity); caches.put(name, cache); } return cache; } }
@Override protected synchronized boolean removeEldestEntry(Map.Entry<K, V> eldest) { return size() > capacity; } }
@Test public void exceededCapacityRemoved() { for (int i = 0; i < TEST_CAPACITY + 1; ++i) { cache.addElement(Integer.toString(i), Integer.toString(i)); } assertEquals(TEST_CAPACITY, cache.size()); assertEquals(TEST_CAPACITY, cache.getSize()); assertEquals(TEST_CAPACITY, cache.getCapacity()); assertNull(cache.getElement("0")); } }
@SuppressWarnings("unchecked") public <K, V> Cache<K, V> createCache(String name) { int capacity = getCapacity(Preconditions.checkNotNull(name)); Cache<K, V> cache = (Cache<K, V>) caches.get(name); if (cache == null) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Creating cache named " + name); } cache = new LruCache<K, V>(capacity); caches.put(name, cache); } return cache; } }
@Override protected synchronized boolean removeEldestEntry(Map.Entry<K, V> eldest) { return size() > capacity; } }
@Test public void normalCapacityOk() { for (int i = 0; i < TEST_CAPACITY; ++i) { cache.addElement(Integer.toString(i), Integer.toString(i)); } assertEquals(TEST_CAPACITY, cache.size()); assertEquals(TEST_CAPACITY, cache.getSize()); assertEquals(TEST_CAPACITY, cache.getCapacity()); assertEquals("0", cache.getElement("0")); }
@Before public void setUp() throws Exception { timeSource = new FakeTimeSource(0); cache = new LruCache<String, String>(5); }
public long getSize() { return size(); }
@Test public void normalCapacityOk() { for (int i = 0; i < TEST_CAPACITY; ++i) { cache.addElement(Integer.toString(i), Integer.toString(i)); } assertEquals(TEST_CAPACITY, cache.size()); assertEquals(TEST_CAPACITY, cache.getSize()); assertEquals(TEST_CAPACITY, cache.getCapacity()); assertEquals("0", cache.getElement("0")); }