public class

InMemoryLRUCache

extends Object
implements Cache<String, V>
java.lang.Object
   ↳ com.kinvey.java.cache.InMemoryLRUCache<T, V>

Class Overview

This is a very simple implementation of a Least-Recently-Used In-Memory Cache.

It utilizes a LinkedHashMaps removeEldestEntry() override to remove older elements.

This implementation is thread-safe. All accessors (get/put) are synchronized on the cache object itself.

Summary

Public Constructors
InMemoryLRUCache()
Use the default cache size and load factor for a new in-memory cache.
InMemoryLRUCache(int cacheSize)
Use a custom cache size but the default load factor for a new in-memory cache.
InMemoryLRUCache(int cacheSize, float loadFactor)
Use a custom cache size and a custom load factor for a new in-memory cache.
Public Methods
V get(T key)
Pull a value from the cache with the associated key.
void put(T key, V value)
Put a Value in the LRUCache with the associated Key This method is threadsafe through java's synchronization.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.kinvey.java.cache.Cache

Public Constructors

public InMemoryLRUCache ()

Use the default cache size and load factor for a new in-memory cache.

the default cacheSize is 16 elements, and the default load factor is 0.75

public InMemoryLRUCache (int cacheSize)

Use a custom cache size but the default load factor for a new in-memory cache.

public InMemoryLRUCache (int cacheSize, float loadFactor)

Use a custom cache size and a custom load factor for a new in-memory cache.

Public Methods

public V get (T key)

Pull a value from the cache with the associated key. This method is threadsafe through java's synchronization.

Parameters
key - the Key of the value to retrieve

public void put (T key, V value)

Put a Value in the LRUCache with the associated Key This method is threadsafe through java's synchronization.

Parameters
key - the Key of the Value to store
value - the Value to store