Skip to content

icecoldaswin/ConcurrentHashMap-based-In-Memory-Cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hashtable-based-In-Memory-Cache
===============================

Intro:
-----

A simple In-Memory KeyValue store that can be instantiated from with-in any Java program. 
Comes with a 'Cleanup thread' that periodically cleans up the Hashtable (based on the TTL for each entry) using
an index (instance of TreeMap collection which is implemented using Red Black tree algorithm)

API methods:
-----------

1. Add (String key, Object value, long TTL) -  
	a. Accepts KeyValue pair along with Time To Live (TTL).

2. Get (String key) - 
	a. Returns an Object associated with this key 
	b. Removes it if expired and throws an exception, "Object expired."
	c. If such a key doesn't exist throws an exception, "Object does not exit/expired."

3. Delete (String key) -
	a. Deletes a record with the given key if it exists and not already expired. Throws an exception otherwise.

Improvements:
------------

1. The frequency of the cleaner needs to be tuned/improved a lot as per the system's needs/capacity

TestCases:
---------

CacheSystemTestCase3 - 

A multi threaded access to the cache. 500 threads calls "add ()" with distict Key-Value pairs, but "get ()" 
with random Keys. i.e,. Concurrent reads and no concurrent writes.

Disclaimer:
----------

* Not tested in large scale

About

In-Memory KeyValue store developed on Java using ConcurrentHashMap

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages