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 Client goes down in case of highloading. #184

Closed studenikin closed 7 years ago

studenikin commented 7 years ago

We tried to highload CacheCow Client and it became unresponsible for some period of time:

The code:

public class MyClient
{
    private readonly HttpClient _client;

    public MyClient(ICacheStore cacheStore)
    {
        _client = new HttpClient(new CachingHandler(cacheStore)
        {
            InnerHandler = new HttpClientHandler()
        });
    }

    public async string GetProducts()
    {
        using (var response = await _client.SendAsync("http://mydomain.com/products"))
        {
            return await response.Content.ReadAsStringAsync();
        }
    }
}

cachecow

When we droped CacheCow Client everything started working fine:

The code:

public class MyClient
{
    private readonly HttpClient _client;

    public MyClient(ICacheStore cacheStore)
    {
        _client = new HttpClient();
    }

    public async string GetProducts()
    {
        using (var response = await _client.SendAsync("http://mydomain.com/products"))
        {
            return await response.Content.ReadAsStringAsync();
        }
    }
}

nocachecow

aliostad commented 7 years ago

Hi, thanks for using and then also reporting the issue. So may I ask what storage are you using? Do you have a repro?

studenikin commented 7 years ago

Hi! We use RedisStore. Not sure what repro is... did you mean source code?

aliostad commented 7 years ago

OK then, can you please use https://www.nuget.org/packages/CacheCow.Client45/ nuget package instead of the original?

The original code was written to support .NET 4.0 and async/await code had to be written with so many hoops. So this one is re-written with async-await and I believe will fix your issue.

Look forward to hearing back from you.

studenikin commented 7 years ago

Thanks for quick answer! We'll give it a try, and I'll get back to you with feedback.

aliostad commented 7 years ago

@studenikin bear in mind this says alpha but I have been using it in production for a year. It is rock solid and I will publish v1.0.0 just now.

aliostad commented 7 years ago

@studenikin OK just published final packages. Please also use the corresponding Redis package: https://www.nuget.org/packages/CacheCow.Client.RedisCacheStore45/1.0.0

studenikin commented 7 years ago

@aliostad We've just performed tests against new packages and...the result is great! Everything works fine and stable. Hereby I'm closing the issue.

aliostad commented 7 years ago

Oh thank you so much! Would be great to see a report from you, hopefully a blog post or something - I doubt anyone used it under this huge load