xyz.ronella.gosu:gcache

A simple gosu implementation of concurrent LRU Map.


License
MIT

Documentation

GCache

A simple gosu implementation of concurrent LRU Map.

Public Constructors

Constructors
ConcurrentLRUCache<TYPE_KEY, TYPE_VALUE>(code : String, maxSize : int, evictLogic : BiConsumer<String, Map.Entry<TYPE_KEY, TYPE_VALUE>>)
ConcurrentLRUCache<TYPE_KEY, TYPE_VALUE>(code : String, maxSize : int, losslessLogic : ILosslessLogic<TYPE_KEY, TYPE_VALUE>)
ConcurrentLRUCache<TYPE_KEY, TYPE_VALUE>(code : String, maxSize : int)
ConcurrentLRUCache<TYPE_KEY, TYPE_VALUE>(maxSize : int, evictLogic : BiConsumer<String,Map.Entry<TYPE_KEY, TYPE_VALUE>>)
ConcurrentLRUCache<TYPE_KEY, TYPE_VALUE>(maxSize : int)

Constructor Parameters

Parameter Type Default Description
code String default The code that groups the Map.Entry.
maxSize int The maximum key count of a particular code group in memory. Anything beyond this limit will trigger either the evictLogic or the losslessLogic.
evictLogic BiConsumer<String, Map.Entry<TYPE_KEY, TYPE_VALUE>> A custom eviction logic.
losslessLogic ILosslessLogic<TYPE_KEY, TYPE_VALUE> DefaultLosslessLogic<TYPE_KEY, TYPE_VALUE> An implementation of ILosslessLogic.

Proprietary Methods

Method Description
public function memCacheSize() : int Returns the size of cache in memory.
public function memCachedKeys() : Set<TYPE_KEY> Returns the keys in memory.
public function memCachedValues() : Collection<TYPE_VALUE> Returns the values in memory.

DefaultLosslessLogic<TYPE_KEY, TYPE_VALUE> Class

An implementation of ILosslessLogic<TYPE_KEY, TYPE_VALUE> that only accepts String as the key and Value that must be tag as Serializable. The work of this class will only start if the maxSize key allocated for memory storage was exceeded. If the key counts is beyond the maxSize indicated, all the key entries that are not used will be serialized to the location defined by the environment variable GCACHE_DIR or if it is not present to your <TMP_DIR>\gcache directory. The extension name of a serialized objects is ser.

Usage

  1. Add the following maven dependency to your gosu project:

    Property Value
    Group ID xyz.ronella.gosu
    Artifact ID gcache
    Version 1.1.0

    Using gradle, this can be added as a dependency entry like the following:

    compile group: 'xyz.ronella.gosu', name: 'gcache', version: '1.1.0'
  2. On your code, once an instance of ConcurrentLRUCache was created, use it like you are using an instance of a Map.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Build

Changelog

Author

  • Ronaldo Webb