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

Implement Http cache #15

Merged
merged 2 commits into from
Aug 15, 2016
Merged

Implement Http cache #15

merged 2 commits into from
Aug 15, 2016

Conversation

JunTaoLuo
Copy link
Contributor

@JunTaoLuo JunTaoLuo commented Aug 5, 2016

todos:

  • Triage items marked with TODO: comment
  • Add more tests

cc @Tratcher @davidfowl

@@ -45,11 +45,17 @@ public void Remove(string key)
}
}

public void Set(string key, object entry)
public void Set(string key, object entry, TimeSpan validUntil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validUntil is a strange name for a TimeSpan

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validFor?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, or expireAfter

@Tratcher
Copy link
Member

Tratcher commented Aug 5, 2016

So far so good.

@JunTaoLuo JunTaoLuo force-pushed the johluo/http-cache-implementation branch from 5cfc0da to fe6ef55 Compare August 5, 2016 19:16
{
var client = server.CreateClient();
var initialResponse = await client.GetAsync("");
client.DefaultRequestHeaders.CacheControl = new System.Net.Http.Headers.CacheControlHeaderValue()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tratcher is there any reason we have our own version of CacheControlHeaderValue? It looks very similar to the one in System.Net.Http.Headers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we cloned most of System.Net.Http.Headers in order to make out-of-band usability and perf improvements.

@JunTaoLuo JunTaoLuo changed the title Implement Http cache [WIP] Implement Http cache Aug 9, 2016
namespace Microsoft.AspNetCore.ResponseCaching
{
public interface IResponseCache
{
object Get(string key);
// TODO: Set expiry policy in the underlying cache?
void Set(string key, object entry);
void Set(string key, object entry, TimeSpan validFor);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need a context object here. What other things will we need to pass?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we need in the context object? Should we add that when we actually need it?

@JunTaoLuo
Copy link
Contributor Author

ping @davidfowl @Tratcher


if (body.Length > 0)
{
await response.Body.WriteAsync(body, 0, body.Length).SupressContext();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get rid of SuppresContext().

// Finalize the cache entry
cachingContext.FinalizeCaching();
cachingContext.FinalizeCachingBody();
}
finally
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catch { disable response caching; throw; }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need, response caching is only completed if everything succeeds. Early exit by default behaves as if caching was disabled.

@JunTaoLuo JunTaoLuo force-pushed the johluo/http-cache-implementation branch from b57dcbe to dc4212c Compare August 12, 2016 22:21
public async Task SendFileAsync(string path, long offset, long? length, CancellationToken cancellation)
{
_responseCacheStream.DisableBuffering();
await _originalSendFileFeature.SendFileAsync(path, offset, length, cancellation);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no async/await required.

@Tratcher
Copy link
Member

:shipit:

@JunTaoLuo JunTaoLuo force-pushed the johluo/http-cache-implementation branch from 4e732b9 to 62aabc1 Compare August 15, 2016 20:00
@JunTaoLuo JunTaoLuo merged commit 62aabc1 into dev Aug 15, 2016
@JunTaoLuo JunTaoLuo deleted the johluo/http-cache-implementation branch August 15, 2016 20:51
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.

5 participants