Object cache with an unlimited number of keys but a limited number of objects

I am looking for a C # object cache library that can implement the following patterns:

  • cache is used to cache objects of a certain type T having a primary key. Example: Person class (with first name, last name, etc.), and the key is PersonId
  • The cache can store an unlimited number of keys. The keys are of type int or long.
  • the cache, however, can only store a limited number of objects of type T. T objects take up a lot of memory, and I cannot have many of these objects in the cache at a time.
  • when overflowing, the cache can serialize objects to a database or file, etc. (fast media), but the cache will still store keys.

I basically need to process more T objects than I can store in memory, and I want to use the cache to quickly find them before storing the results in a database.

So, I was thinking about using a Proxy template and had cache proxy objects that can receive / serialize my real objects.

Do you know any C # caching library that can be used with these templates? I myself could not find anything.

thanks

+4
source share
1 answer

What you are looking for is a database. Database mechanisms are designed so that separate key tables and object tables are separated. (If you are not familiar with this concept, search the Internet for information on indexing the database, primary keys, etc.). They are also designed to store pages of key tables in RAM and recently used objects in RAM. In fact, many database engines allow you to configure how many of them you will store in RAM. I think you should use Sqlite with a light ORM (e.g. Dapper or ServiceStack.OrmLite or one of several others). Sqlite has a parameter to disable disk synchronization and two other parameters for adjusting the amount of data in RAM. See the information here: http://www.sqlite.org/pragma.html

0
source

Source: https://habr.com/ru/post/1398727/


All Articles