-
Notifications
You must be signed in to change notification settings - Fork 0
/
docs.txt
19 lines (18 loc) · 1.37 KB
/
docs.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
We are working on a package for caching data. The main type in the package is called "SmartCache". Here's it's description:
SmartCache:
- Contains an in-memory cache of type "*T". The T type is generic.
- Has a "primaryTTL" attribute
- It describes a time after which the cache should be refreshed, but data can still be returned from cache
- Has a "secondaryTTL" attribute:
- It describes a time after which the cache should be refreshed, and cache can't be used to return data
- Has a "cacheErrFunc" which is a function that given the error returns a ttl of the cache with error
- if the function returns ttl > 0, function error should be returned from the cache for that period of time
- Has a "Get" method, that:
- Accepts a context
- Accepts a key
- Accepts a fetch function
- If there's no data in cache: calls fetch function, updates the cache and returns the result
- If there's data in cache and primaryTTL is not expired: returns the cached data
- If there's data in cache, primaryTTL is expired but secondaryTTL is not expired: returns the data from cache and does cache update in the background by calling fetch function
- If there's data in cache and all TTLs are expired: works as if there's no data in cache
- When called and a cache update for the same key is still running in the background, it should wait for the results in the cache