-
Notifications
You must be signed in to change notification settings - Fork 39
Use private instance of MemoryCache and impose size limit #132
Conversation
@@ -11,7 +11,7 @@ public interface IResponseCache | |||
IResponseCacheEntry Get(string key); | |||
Task<IResponseCacheEntry> GetAsync(string key); | |||
|
|||
void Set(string key, IResponseCacheEntry entry, TimeSpan validFor); | |||
Task SetAsync(string key, IResponseCacheEntry entry, TimeSpan validFor); | |||
void Set(string key, IResponseCacheEntry entry, TimeSpan validFor, long size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking into refactoring the helpers to the interface does not change.
options, | ||
loggerFactory, | ||
policyProvider, | ||
new MemoryResponseCache(new MemoryCache(new MemoryCacheOptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, we can add the MemoryResponseCache to DI but have it resolve ResponseCachingOptions to figure out the size.
@@ -9,6 +9,11 @@ namespace Microsoft.AspNetCore.ResponseCaching | |||
public class ResponseCachingOptions | |||
{ | |||
/// <summary> | |||
/// The size limit for the response cache middleware in bytes. The default is set to 100 MB. | |||
/// </summary> | |||
public long SizeLimit { get; set; } = 100 * 1024 * 1024; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have ResponseCachingOptions extend MemoryCacheOptions so other options can be set?
// Body | ||
if (cachedResponse.Body != null) | ||
{ | ||
size += cachedResponse.Body.Length * sizeof(char); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bytes, not chars.
context.CachedResponseValidFor, | ||
EstimateCachedResponseSize(context.CachedResponse)); | ||
} | ||
catch (OverflowException) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't bother, we'll run out of RAM first.
bb3867c
to
2614ab0
Compare
🆙📅 |
2614ab0
to
f125329
Compare
Addresses #127 Still need to add some tests.