{"id":13414861,"url":"https://github.com/joakimskoog/Cashew","last_synced_at":"2025-03-14T22:32:22.569Z","repository":{"id":144187103,"uuid":"91880070","full_name":"joakimskoog/Cashew","owner":"joakimskoog","description":"A simple and elegant yet powerful HTTP client cache for .NET","archived":false,"fork":false,"pushed_at":"2020-02-13T20:18:34.000Z","size":74,"stargazers_count":83,"open_issues_count":6,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-06T10:38:53.409Z","etag":null,"topics":["cache","caching","cashew","etag","http","http-client","httpclient"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joakimskoog.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-05-20T09:51:55.000Z","updated_at":"2023-09-25T02:57:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"badc1a57-ceaf-4a55-9b38-ae0049db0af6","html_url":"https://github.com/joakimskoog/Cashew","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joakimskoog%2FCashew","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joakimskoog%2FCashew/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joakimskoog%2FCashew/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joakimskoog%2FCashew/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joakimskoog","download_url":"https://codeload.github.com/joakimskoog/Cashew/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221513933,"owners_count":16835746,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","caching","cashew","etag","http","http-client","httpclient"],"created_at":"2024-07-30T21:00:38.612Z","updated_at":"2024-10-26T08:30:38.090Z","avatar_url":"https://github.com/joakimskoog.png","language":"C#","funding_links":[],"categories":["Caching","缓存"],"sub_categories":[],"readme":"# Cashew\nCashew is a .NET library for caching responses easily with an HttpClient through an API that is simple and elegant yet powerful.\nThere's support out of the box for the awesome [CacheManager](https://github.com/MichaCo/CacheManager) via the `Cashew.Adapters.CacheManager` package. Its aim is to focus on the HTTP part of caching and not worrying about how stuff is stored, meaning no half-arsed cache implementations!\n\nCashew targets .NET 4.5 and .NET Standard 1.1 (.NET Core, Mono, Xamarin.iOS, Xamarin.Android, UWP and [more](https://github.com/dotnet/standard/blob/master/docs/versions.md)) meaning it can be used on all sorts of devices.\n\n[![Build Status](https://ci.appveyor.com/api/projects/status/github/joakimskoog/Cashew?branch=release\u0026svg=true\n)](https://ci.appveyor.com/project/joakimskoog/cashew/history)\n[![NuGet](https://img.shields.io/nuget/v/Cashew.svg)](https://www.nuget.org/packages/Cashew/)\n\n![Cashew-logo](https://raw.githubusercontent.com/joakimskoog/Cashew/master/Cashew-Logo.png)\n\n# Installation\nThe latest versions of the packages are available on NuGet. To install, run the following command if you want to roll your own cache:\n```\nPM\u003e Install-Package Cashew\n```\nor the command below if you want to utilise the power of [CacheManager](https://github.com/MichaCo/CacheManager)\n```\nPM\u003e Install-Package Cashew.Adapters.CacheManager\n```\n\n# Features\n\n\n## General features\n- Extremely easy to use, all it takes is one line to configure the whole thing!\n- Simple but powerful API that allows customisation\n- [ETag support](https://en.wikipedia.org/wiki/HTTP_ETag)\n- [Vary Header support](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary)\n\n## Cache stores\n\n|Type|Out of the box?|\n| ------------- | ------------- |\n|Dictionary|Yes*|\n|[System.Runtime.Caching.MemoryCache](https://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache(v=vs.110).aspx)|Yes*|\n|[Microsoft.Extensions.Caching.Memory](https://github.com/aspnet/Caching/tree/master/src/Microsoft.Extensions.Caching.Memory)|Yes*|\n| [Redis](https://www.nuget.org/packages/CacheManager.StackExchange.Redis) |Yes*|\n| [Memcached](https://www.nuget.org/packages/CacheManager.Memcached) |Yes*|\n| [Couchbase](https://www.nuget.org/packages/CacheManager.Couchbase) |Yes*|\n| Custom | [No, but it's super easy to implement your own](https://github.com/joakimskoog/Cashew/wiki/Custom-cache).| \n\n*Provided that you use `Cashew.Adapters.CacheManager`\n\n## HTTP Cache-Control Headers\n|Header|Aka|\n| ------------- | ------------- |\n|[max-age](https://tools.ietf.org/html/rfc7234)|\"I don't want cached responses older than this\"|\n|[s-maxage](https://tools.ietf.org/html/rfc7234)|\"I don't want cached responses older than this\"| \n|[max-stale](https://tools.ietf.org/html/rfc7234)|\"Stale responses are OK for this long\"| \n|[min-fresh](https://tools.ietf.org/html/rfc7234)|\"The response has to still be fresh for at least this long\"| \n|[no-cache](https://tools.ietf.org/html/rfc7234)|\"You must validate the cached response with the server| \n|[no-store](https://tools.ietf.org/html/rfc7234)|\"DO NOT CACHE THIS OR I WILL MAKE YOUR LIFE MISERABLE!\"| \n|[only-if-cached](https://tools.ietf.org/html/rfc7234)|\"I only want a response if it's cached\"| \n|[must-revalidate](https://tools.ietf.org/html/rfc7234)|\"You MUST revalidate stale responses\"| \n|[proxy-revalidate](https://tools.ietf.org/html/rfc7234)|\"You MUST revalidate stale responses\"| \n\n## Customisation\nCashew provides a lot of customisation opportunities for its users. The most important ones are listed below:\n\n|Feature|Quickstart|In-depth|\n| ------------- | ------------- | ------------- |\n| Use any cache store | [Link](#use-any-cache-store) | [Wiki](https://github.com/joakimskoog/Cashew/wiki/Custom-cache) |\n| Decide how cache keys are created | [Link](#decide-how-cache-keys-are-created) | [Wiki](https://github.com/joakimskoog/Cashew/wiki/CacheKeyStrategy) |\n| Decide which status codes are cacheable | [Link](#cacheable-status-codes) | [Wiki](https://github.com/joakimskoog/Cashew/wiki/HTTP-Status-Codes) |\n\n# Usage\nFor more in-depth information on how to use Cashew, please refer to our [wiki](https://github.com/joakimskoog/Cashew/wiki).\n\n## Configuring HttpClient\n```csharp\n//All it takes is one line to configure the whole thing!\nvar httpClient = new HttpClient(new HttpCachingHandler(cache, new HttpStandardKeyStrategy(cache)));\n```\n\n\n## Use any cache store\n```csharp\n//We feel like caching the HTTP responses in an SQL store (for some reason) and have therefore created our own SqlCache\nvar sqlCache = new SqlCache();\n\n//We pass our newly created sql cache in the constructor and watch the magic happen\nvar httpCachingHandler = new HttpCachingHandler(sqlCache, keyStrategy);\n```\n\n## Decide how cache keys are created\n```csharp\n//We have created our own strategy that creates keys out of request URI:s\nvar uriKeyStrategy = new RequestUriKeyStrategy();\n\n//We pass our newly created key strategy in the constructor and watch the magic happen!\nvar httpCachingHandler = new HttpCachingHandler(memoryCache, uriKeyStrategy);\n```\n\n## Decide how query strings are handled\n```csharp\n//The default implementation of ICacheKeyStrategy is HttpStandardKeyStrategy. You can configure it to handle query strings in two ways.\n\n//Using CacheKeySetting.Standard will result in a different cache key each time the query string changes\nvar queryStringStrategy = new HttpStandardKeyStrategy(cache, CacheKeySetting.Standard);\n\n//Using CacheKeySetting.IgnoreQueryString will result in the same key even if the query string changes.\nvar uriStrategy = new HttpStandardKeyStrategy(cache, CacheKeySetting.IgnoreQueryString);\n```\n\n## Cacheable status codes\n```csharp\n//We only want to cache responses with status 200\nhttpCachingHandler.CacheableStatusCodes = new[] { HttpStatusCode.OK };\n```\n\n# Contributing\nPlease refer to our [guidelines](https://github.com/joakimskoog/Cashew/wiki/Contributing) on contributing.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoakimskoog%2FCashew","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoakimskoog%2FCashew","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoakimskoog%2FCashew/lists"}