Skip to content

serhii-bohutskyi/cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Cache

Simple Cache is implementation of base cache logic with different storages. To use cache implement your Storage or use default MemoryStorage.

Simple Application

User user =...
String name = ...

//create manager        
CacheManager cacheManager = new CacheManager();
//get user cache 
Cache<String, User> userCache = cacheManager.getCache("UserCache");

//put into cache        
userCache.put(name, user);
//get from cache
User user = userCache.get(name);

Application with TreeStorage

User user =...
String name = ...

//create manager        
CacheManager cacheManager = new CacheManager();
//get user cache 
Cache<String, User> userCache = cacheManager.getCache("UserCache", new TreeStorage());

//put into cache        
userCache.put(name, user);
//get from cache
User user = userCache.get(name);

The Cache Interface

Cache interface describes simple operations. See the methods below.

public interface Cache<K, V> {
    V get(K key);
    void put(K key, V value);
    String getName();
    boolean isClosed();
    void close();
}

The Storage Interface

Storage interface describes basic methods to store key-value pair. See the methods below.

public interface Storage<K, V> {
    void save(K key, V value);
    V load(K key);
}

Storage Implementations

LruStorage - A Least Recently Used Implementation

MruStorage - A Most Recently Used Implementation.

TreeStorage - A Tree Implementation.

Storage implementation can be such as memory storage, file storage, database storage, etc. Its implementation depends on your need. For example you can use different memory storages with more or less productive algorithms.

About

Cache implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published