Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A simple and elegant yet powerful HTTP client cache for .NET

License

NotificationsYou must be signed in to change notification settings

joakimskoog/Cashew

Repository files navigation

Cashew is a .NET library for caching responses easily with an HttpClient through an API that is simple and elegant yet powerful.There's support out of the box for the awesomeCacheManager via theCashew.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!

Cashew targets .NET 4.5 and .NET Standard 1.1 (.NET Core, Mono, Xamarin.iOS, Xamarin.Android, UWP andmore) meaning it can be used on all sorts of devices.

Build StatusNuGet

Cashew-logo

Installation

The latest versions of the packages are available on NuGet. To install, run the following command if you want to roll your own cache:

PM> Install-Package Cashew

or the command below if you want to utilise the power ofCacheManager

PM> Install-Package Cashew.Adapters.CacheManager

Features

General features

  • Extremely easy to use, all it takes is one line to configure the whole thing!
  • Simple but powerful API that allows customisation
  • ETag support
  • Vary Header support

Cache stores

TypeOut of the box?
DictionaryYes*
System.Runtime.Caching.MemoryCacheYes*
Microsoft.Extensions.Caching.MemoryYes*
RedisYes*
MemcachedYes*
CouchbaseYes*
CustomNo, but it's super easy to implement your own.

*Provided that you useCashew.Adapters.CacheManager

HTTP Cache-Control Headers

HeaderAka
max-age"I don't want cached responses older than this"
s-maxage"I don't want cached responses older than this"
max-stale"Stale responses are OK for this long"
min-fresh"The response has to still be fresh for at least this long"
no-cache"You must validate the cached response with the server
no-store"DO NOT CACHE THIS OR I WILL MAKE YOUR LIFE MISERABLE!"
only-if-cached"I only want a response if it's cached"
must-revalidate"You MUST revalidate stale responses"
proxy-revalidate"You MUST revalidate stale responses"

Customisation

Cashew provides a lot of customisation opportunities for its users. The most important ones are listed below:

FeatureQuickstartIn-depth
Use any cache storeLinkWiki
Decide how cache keys are createdLinkWiki
Decide which status codes are cacheableLinkWiki

Usage

For more in-depth information on how to use Cashew, please refer to ourwiki.

Configuring HttpClient

//All it takes is one line to configure the whole thing!varhttpClient=newHttpClient(newHttpCachingHandler(cache,newHttpStandardKeyStrategy(cache)));

Use any cache store

//We feel like caching the HTTP responses in an SQL store (for some reason) and have therefore created our own SqlCachevarsqlCache=newSqlCache();//We pass our newly created sql cache in the constructor and watch the magic happenvarhttpCachingHandler=newHttpCachingHandler(sqlCache,keyStrategy);

Decide how cache keys are created

//We have created our own strategy that creates keys out of request URI:svaruriKeyStrategy=newRequestUriKeyStrategy();//We pass our newly created key strategy in the constructor and watch the magic happen!varhttpCachingHandler=newHttpCachingHandler(memoryCache,uriKeyStrategy);

Decide how query strings are handled

//The default implementation of ICacheKeyStrategy is HttpStandardKeyStrategy. You can configure it to handle query strings in two ways.//Using CacheKeySetting.Standard will result in a different cache key each time the query string changesvarqueryStringStrategy=newHttpStandardKeyStrategy(cache,CacheKeySetting.Standard);//Using CacheKeySetting.IgnoreQueryString will result in the same key even if the query string changes.varuriStrategy=newHttpStandardKeyStrategy(cache,CacheKeySetting.IgnoreQueryString);

Cacheable status codes

//We only want to cache responses with status 200httpCachingHandler.CacheableStatusCodes=new[]{HttpStatusCode.OK};

Contributing

Please refer to ourguidelines on contributing.

About

A simple and elegant yet powerful HTTP client cache for .NET

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp