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

Use private instance of MemoryCache and impose size limit #132

Merged
merged 1 commit into from
Jul 10, 2017

Conversation

JunTaoLuo
Copy link
Contributor

@JunTaoLuo JunTaoLuo commented Jul 10, 2017

Addresses #127 Still need to add some tests.

@@ -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);
Copy link
Contributor Author

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
Copy link
Contributor Author

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;
Copy link
Contributor Author

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);
Copy link
Member

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) { }
Copy link
Member

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.

@JunTaoLuo JunTaoLuo force-pushed the johluo/size-limit branch 2 times, most recently from bb3867c to 2614ab0 Compare July 10, 2017 21:55
@JunTaoLuo
Copy link
Contributor Author

🆙📅

@JunTaoLuo JunTaoLuo force-pushed the johluo/size-limit branch from 2614ab0 to f125329 Compare July 10, 2017 22:15
@JunTaoLuo JunTaoLuo changed the base branch from dev to rel/2.0.0 July 10, 2017 22:15
@JunTaoLuo JunTaoLuo merged commit f125329 into rel/2.0.0 Jul 10, 2017
@JunTaoLuo JunTaoLuo deleted the johluo/size-limit branch July 10, 2017 23:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants