ByteStash is an easy to use inbuilt java cache library that is customizable in every aspect, inspiring from Memcached implementation with multi node capability running on different threads. This cache just like Memcached has three regions hot,warm and cold, refer Memcached Implementation for more reference.
- Build the project by taking a clone of main branch and using java 8+ so that all the dependencies are downloaded.
- Once the jar is installed, use this jar as dependency in your project.
<dependency>
<groupId>org.rb98dps</groupId>
<artifactId>byte-stash</artifactId>
<version>1.0</version>
</dependency>- To create the ByteStash caching, use
ByteStashFactoryto create an Instance ofByteStashwith customizable attributes.
ByteStashFactory<Object> byteStashFactory = ByteStashFactory.builder().withNodes(5).withCapacity(50000L).withTimeToLive(100L)
.withHotPercent(0.1f).withWarmPercent(0.2f).withQueueSize(1000).build();
ByteStash<Object> byteStash = byteStashFactory.getByteStash();- Generic type
Objectis used to store any type of data in the cache, it can be changed to store only specific type of data
import org.bytestash.creator.ByteStashFactory;
import org.bytestash.creator.ByteStashManager;
ByteStashFactory<CustomObject> byteStashFactory = ByteStashFactory.builder().withNodes(5).withCapacity(50000L).
withTimeToLive(100L)
.withHotPercent(0.1f).withWarmPercent(0.2f).withQueueSize(1000).build();
ByteStashManager<CustomObject> byteStashManager = byteStashFactory.create();-
Cache can customize the hot percentage and warm percentage just like in memcached, Other attributes that can be customized are:
- Number of nodes can be customized with max limit of 12, all nodes will run on separate threads
- Capacity of the number of items can be adjusted to your choice with a minimum value, if not provided default value will be used
- Time to Live for the item stored in any node, value taken is in seconds
- For every 4 nodes, one Crawler is created.
- Queue size for the Crawler that cleans the cache and remove the expired items in every node.
-
Storing of any object is easy, just call the put method defined in ByteStash object that was created before
byteStashManager.put(keyObject, storeObject.class);
- So is the retrieving of the Object back from the cache, give the key Object and class type of the object stored, we can store multiple type of object related to same key. The manager will return a value of Type defined during definition of the ByteStash.
StoringObject storingObject = (StoringObject) byteStashManager.get(keyObject, StoringObject.class);To be updated soon
Further progress can be made in these areas:-
- There is a scope for enhancement with giving the type of eviction policy to the user,other than time based policy.
- Performance can be improved by using a better serialization library
- The number of nodes supported by the system is fixed, Cache should be able to increase or decrease number of nodes for efficiency.
