mercredi 28 octobre 2015

General purpose cache with replaceable algorithm

I am aiming to implement a cache in java, such that the user of the cache to determine which algorithm to use for this cache. This can be a general purpose cache and user can decide to use it as LRU or MRU or some other strategy.

which would be a good design pattern for this? Goal is to encapsulate all my internal data structures that I use for cache at the same time exposing right interfaces so user of the cache can plug-in their own caching algorithm ( LRU, MRU, etc.)

I am inclined towards using dependency injection, and injecting a "delegate" to the constructor of the cache, such that this delegate would govern which caching strategy is implemented.

Just wanted to check if there are any thoughts/suggestions on this design so that I can have a clean separation betweeen (a) the cache implementaion ( and internal datastrctures) and (b) actual caching strategy.

Thanks a bunch in advance.

Aucun commentaire:

Enregistrer un commentaire