aliostad / CacheCow

An implementation of HTTP Caching in .NET Core and 4.5.2+ for both the client and the server
MIT License
847 stars 172 forks source link

CacheCow is not caching (.NET 5.0) #263

Closed matteoventuri7 closed 2 years ago

matteoventuri7 commented 3 years ago

This unit test fail on .NET 5.0

var client = ClientExtensions.CreateClient();
const string CacheableResource = "https://code.jquery.com/jquery-3.3.1.slim.min.js";
var response = await client.GetAsync(CacheableResource);
var responseFromCache = await client.GetAsync(CacheableResource);
Assert.AreEqual(false, response.Headers.GetCacheCowHeader().RetrievedFromCache);
Assert.AreEqual(true, responseFromCache.Headers.GetCacheCowHeader().RetrievedFromCache);
aliostad commented 3 years ago

Thanks for reporting. I will look into it but have a feeling is related to https://github.com/aliostad/CacheCow/issues/213 which is just fixed during .NET 5.0.

They tried to fix it twice they messed up twice. This will be the 3rd time.

aliostad commented 2 years ago

OK, apologies for not being able to look into it.

There is no problem in .NET 5.0, one of the tests do not work which I am looking into.

As for your example your assert is wrong. It fails on first time round in fact, since you expect false while it is null. Change it so you can see:

        [Fact]
        public async Task Simple_Caching_Example_From_Issue263()
        {
            var client = ClientExtensions.CreateClient();
            const string CacheableResource = "https://code.jquery.com/jquery-3.3.1.slim.min.js";
            var response = await client.GetAsync(CacheableResource);
            var responseFromCache = await client.GetAsync(CacheableResource);
            Assert.Equal(true, response.Headers.GetCacheCowHeader().DidNotExist);
            Assert.Equal(true, responseFromCache.Headers.GetCacheCowHeader().RetrievedFromCache);
        }