Ram
Ram

Reputation: 46

Design pattern to replace a cache

In our program we store a large volume of data in a cache. The cache is a Dictionary. As large volume of data is in-memory, we plan to use a database instead of dictionary. So all data that was once in the dictionary will be moved to a table in database. Now the problem is, the dictionary cache is been used in many places in the project. Please suggest me a design pattern to effectively replace the dictionary cache with database with minimal code changes.

The cache will be like Dictionary(string, MyBusinessObject). The dictionary key will be 'Id'. MyBusinessObject will have the data in it's properties. Eg- myBusinessObject.CustomerName, myBusinessObject.CustomerAge. Throughout my project, various modules will search for the Id (key) in the dictionary.

Upvotes: 3

Views: 1187

Answers (2)

Ed Power
Ed Power

Reputation: 8531

Have you considered PersistentDictionary? It's open-source Dictionary that's built on top of the ESENT database engine. You get to use Dictionary that can store up to 16TB.

Upvotes: 3

rerun
rerun

Reputation: 25505

Dictionary implements the IDictionary<TKey, TValue> You should create a facade over the database that also implements the IDictionary<TKey, TValue> Then making sure you no longer use the concrete dictionary. Lastly you will need to create a factory for the new abstraction which will allow you to replace it with a mock for testing.

Upvotes: 9

Related Questions