All Projects → joakimskoog → Cashew

joakimskoog / Cashew

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

Projects that are alternatives of or similar to Cashew

Nebulex
In-memory and distributed caching toolkit for Elixir.
Stars: ✭ 662 (+845.71%)
Mutual labels:  cache, caching
Cache Service Provider
A Cache Service Provider for Silex, using the doctrine/cache package
Stars: ✭ 23 (-67.14%)
Mutual labels:  cache, caching
Restclient
🦄 Simple HTTP and REST client for Unity based on Promises, also supports Callbacks! 🎮
Stars: ✭ 675 (+864.29%)
Mutual labels:  http-client, httpclient
Bigcache
Efficient cache for gigabytes of data written in Go.
Stars: ✭ 5,304 (+7477.14%)
Mutual labels:  cache, caching
Synchrotron
Caching layer load balancer.
Stars: ✭ 42 (-40%)
Mutual labels:  cache, caching
Cached
Rust cache structures and easy function memoization
Stars: ✭ 530 (+657.14%)
Mutual labels:  cache, caching
Httpcache
Get a working HTTP Cache in Go (Golang) with only 3 lines of code!!!!
Stars: ✭ 17 (-75.71%)
Mutual labels:  cache, http-client
Stackexchange.redis.extensions
Stars: ✭ 419 (+498.57%)
Mutual labels:  cache, caching
Use Axios Request
Data fetching is easy with React Hooks for axios!
Stars: ✭ 38 (-45.71%)
Mutual labels:  cache, http-client
Request.swift
A tiny HTTP client written in swift. URLSession alternative
Stars: ✭ 14 (-80%)
Mutual labels:  http-client, httpclient
Guzzle
Guzzle, an extensible PHP HTTP client
Stars: ✭ 21,384 (+30448.57%)
Mutual labels:  http-client, httpclient
Fastcache
Fast thread-safe inmemory cache for big number of entries in Go. Minimizes GC overhead
Stars: ✭ 1,051 (+1401.43%)
Mutual labels:  cache, caching
Libmc
Fast and light-weight memcached client for C++ / #python / #golang #libmc
Stars: ✭ 429 (+512.86%)
Mutual labels:  cache, caching
Urllib
Request HTTP(s) URLs in a complex world
Stars: ✭ 600 (+757.14%)
Mutual labels:  http-client, httpclient
Lada Cache
A Redis based, fully automated and scalable database cache layer for Laravel
Stars: ✭ 424 (+505.71%)
Mutual labels:  cache, caching
Gout
gout to become the Swiss Army Knife of the http client @^^@---> gout 是http client领域的瑞士军刀,小巧,强大,犀利。具体用法可看文档,如使用迷惑或者API用得不爽都可提issues
Stars: ✭ 749 (+970%)
Mutual labels:  http-client, httpclient
Memento
Memento is a development-only tool that caches HTTP calls once they have been executed.
Stars: ✭ 380 (+442.86%)
Mutual labels:  cache, caching
Wp Rocket
Performance optimization plugin for WordPress
Stars: ✭ 394 (+462.86%)
Mutual labels:  cache, caching
Rw File Cache
🗄️ PHP File-based Caching Library
Stars: ✭ 10 (-85.71%)
Mutual labels:  cache, caching
Easycaching
💥 EasyCaching is an open source caching library that contains basic usages and some advanced usages of caching which can help us to handle caching more easier!
Stars: ✭ 1,047 (+1395.71%)
Mutual labels:  cache, caching

Cashew

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 awesome 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!

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

Build Status NuGet

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 of CacheManager

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

Type Out of the box?
Dictionary Yes*
System.Runtime.Caching.MemoryCache Yes*
Microsoft.Extensions.Caching.Memory Yes*
Redis Yes*
Memcached Yes*
Couchbase Yes*
Custom No, but it's super easy to implement your own.

*Provided that you use Cashew.Adapters.CacheManager

HTTP Cache-Control Headers

Header Aka
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:

Feature Quickstart In-depth
Use any cache store Link Wiki
Decide how cache keys are created Link Wiki
Decide which status codes are cacheable Link Wiki

Usage

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

Configuring HttpClient

//All it takes is one line to configure the whole thing!
var httpClient = new HttpClient(new HttpCachingHandler(cache, new HttpStandardKeyStrategy(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 SqlCache
var sqlCache = new SqlCache();

//We pass our newly created sql cache in the constructor and watch the magic happen
var httpCachingHandler = new HttpCachingHandler(sqlCache, keyStrategy);

Decide how cache keys are created

//We have created our own strategy that creates keys out of request URI:s
var uriKeyStrategy = new RequestUriKeyStrategy();

//We pass our newly created key strategy in the constructor and watch the magic happen!
var httpCachingHandler = new HttpCachingHandler(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 changes
var queryStringStrategy = new HttpStandardKeyStrategy(cache, CacheKeySetting.Standard);

//Using CacheKeySetting.IgnoreQueryString will result in the same key even if the query string changes.
var uriStrategy = new HttpStandardKeyStrategy(cache, CacheKeySetting.IgnoreQueryString);

Cacheable status codes

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

Contributing

Please refer to our guidelines on contributing.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].