Skip to content

Commit

Permalink
Create CACHING.md
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-scherbina authored Oct 16, 2023
1 parent 97a2c16 commit 27b079b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions architecture/CACHING.md
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit 27b079b

Please sign in to comment.