Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Size hint based eviction for MemoryCache #326

Closed
JunTaoLuo opened this issue Jun 29, 2017 · 3 comments
Closed

Size hint based eviction for MemoryCache #326

JunTaoLuo opened this issue Jun 29, 2017 · 3 comments
Assignees
Milestone

Comments

@JunTaoLuo
Copy link
Contributor

Following up on #325.

MemoryCache does not know the size of the items it caches but the user of MemoryCache may know the size. In those cases we want to provide a method for size based eviction to guarantee a limit on the memory footprint of the cache. We can also add an option to require size hint when adding an item to the memory cache. Having a size hint also gives us the opportunity to investigate different eviction policies.

@Tratcher
Copy link
Member

Recommended for 2.1

@javiercn
Copy link
Member

javiercn commented Jul 5, 2017

Some notes from our discussion:

  • Make sure we don't register MemoryDistributeCache on our components.
  • Deprecate/remove the AddDistributedMemoryCache extension method. (Also update the comment to reflect that if this method is used, the cache will be shared among all IDistributedCache consumers).
  • Force a size limit on DistributedMemoryCache
  • Have each of our components on the framework that consume IDistributedCache create their own private version of the DistributedMemoryCache if no implementation is registered. The configuration on the limits for these instances can be exposed through named options or through some wrapper/new extension method on a case by case basis.
  • Have the MemoryDistributedCache tell the size of the entries to the underlying MemoryCache when adding entries.

Sample new extension method for session:

services.AddInMemorySession(options => options.MaxSize = 10 * 1024 * 1024);

Sample configuration through named options for the DistributedCacheTagHelper

services.AddMvc();
services.Configure(Some.Constant, options => options.MaxSize = 10 * 1024 * 1024);

@Tratcher @davidfowl @JunTaoLuo

@JunTaoLuo
Copy link
Contributor Author

JunTaoLuo commented Jul 8, 2017

@javiercn the updated POR is collected in #329

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants