From 27b079bc64b7c29e6c6d84bdccbaf0f314ac1a07 Mon Sep 17 00:00:00 2001 From: Evgeniy Scherbina Date: Mon, 16 Oct 2023 15:36:54 -0400 Subject: [PATCH] Create CACHING.md --- architecture/CACHING.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 architecture/CACHING.md diff --git a/architecture/CACHING.md b/architecture/CACHING.md new file mode 100644 index 0000000..203a902 --- /dev/null +++ b/architecture/CACHING.md @@ -0,0 +1,33 @@ +## Caching Middleware Architecture + +Package `cachemdw` is responsible for caching EVM requests and provides corresponding middleware + +package can work with any underlying storage which implements simple `cache.Cache` interface + +package provides two different middlewares: +- `IsCachedMiddleware` (should be run before proxy middleware) +- `CachingMiddleware` (should be run after proxy middleware) + +`IsCachedMiddleware` is responsible for setting response in the context if it's in the cache + +`CachingMiddleware` is responsible for caching response by taking a value from context (should be set by `ProxyMiddleware`) and setting in the cache + +## CachingMiddleware + +`CachingMiddleware` returns kava-proxy-service compatible middleware which works in the following way: +- tries to get decoded request from context (previous middleware should set it) +- checks few conditions: + - if request isn't already cached + - if request is cacheable + - if response is present in context +- if all above is true - caches the response +- calls next middleware + +## IsCachedMiddleware + +`IsCachedMiddleware` returns kava-proxy-service compatible middleware which works in the following way: +- tries to get decoded request from context (previous middleware should set it) +- tries to get response from the cache + - if present sets cached response in context, marks as cached in context and forwards to next middleware + - if not present marks as uncached in context and forwards to next middleware +- next middleware should check whether request was cached and act accordingly: