-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97a2c16
commit 27b079b
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |