From 7cc40302a578264dff4edb3b007fc192b840c7d4 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Sun, 10 Jul 2022 16:18:21 +0100 Subject: [chore] consolidate caching libraries (#704) * add miekg/dns dependency * set/validate accountDomain * move finger to dereferencer * totally break GetRemoteAccount * start reworking finger func a bit * start reworking getRemoteAccount a bit * move mention parts to namestring * rework webfingerget * use util function to extract webfinger parts * use accountDomain * rework finger again, final form * just a real nasty commit, the worst * remove refresh from account * use new ASRepToAccount signature * fix incorrect debug call * fix for new getRemoteAccount * rework GetRemoteAccount * start updating tests to remove repetition * break a lot of tests Move shared test logic into the testrig, rather than having it scattered all over the place. This allows us to just mock the transport controller once, and have all tests use it (unless they need not to for some other reason). * fix up tests to use main mock httpclient * webfinger only if necessary * cheeky linting with the lads * update mentionName regex recognize instance accounts * don't finger instance accounts * test webfinger part extraction * increase default worker count to 4 per cpu * don't repeat regex parsing * final search for discovered accountDomain * be more permissive in namestring lookup * add more extraction tests * simplify GetParseMentionFunc * skip long search if local account * fix broken test * consolidate to all use same caching libraries Signed-off-by: kim * perform more caching in the database layer Signed-off-by: kim * remove ASNote cache Signed-off-by: kim * update cache library, improve db tracing hooks Signed-off-by: kim * return ErrNoEntries if no account status IDs found, small formatting changes Signed-off-by: kim * fix tests, thanks tobi! Signed-off-by: kim Co-authored-by: tsmethurst --- vendor/github.com/ReneKroon/ttlcache/Readme.md | 71 -------------------------- 1 file changed, 71 deletions(-) delete mode 100644 vendor/github.com/ReneKroon/ttlcache/Readme.md (limited to 'vendor/github.com/ReneKroon/ttlcache/Readme.md') diff --git a/vendor/github.com/ReneKroon/ttlcache/Readme.md b/vendor/github.com/ReneKroon/ttlcache/Readme.md deleted file mode 100644 index 9c537fbdc..000000000 --- a/vendor/github.com/ReneKroon/ttlcache/Readme.md +++ /dev/null @@ -1,71 +0,0 @@ -## TTLCache - an in-memory cache with expiration - -TTLCache is a simple key/value cache in golang with the following functions: - -1. Thread-safe -2. Individual expiring time or global expiring time, you can choose -3. Auto-Extending expiration on `Get` -or- DNS style TTL, see `SkipTtlExtensionOnHit(bool)` -4. Fast and memory efficient -5. Can trigger callback on key expiration -6. Cleanup resources by calling `Close()` at end of lifecycle. - -Note (issue #25): by default, due to historic reasons, the TTL will be reset on each cache hit and you need to explicitly configure the cache to use a TTL that will not get extended. - -[![Build Status](https://travis-ci.org/ReneKroon/ttlcache.svg?branch=master)](https://travis-ci.org/ReneKroon/ttlcache) - -#### Usage -```go -import ( - "time" - "fmt" - - "github.com/ReneKroon/ttlcache" -) - -func main () { - newItemCallback := func(key string, value interface{}) { - fmt.Printf("New key(%s) added\n", key) - } - checkExpirationCallback := func(key string, value interface{}) bool { - if key == "key1" { - // if the key equals "key1", the value - // will not be allowed to expire - return false - } - // all other values are allowed to expire - return true - } - expirationCallback := func(key string, value interface{}) { - fmt.Printf("This key(%s) has expired\n", key) - } - - cache := ttlcache.NewCache() - defer cache.Close() - cache.SetTTL(time.Duration(10 * time.Second)) - cache.SetExpirationCallback(expirationCallback) - - cache.Set("key", "value") - cache.SetWithTTL("keyWithTTL", "value", 10 * time.Second) - - value, exists := cache.Get("key") - count := cache.Count() - result := cache.Remove("key") -} -``` - -#### TTLCache - Some design considerations - -1. The complexity of the current cache is already quite high. Therefore i will not add 'convenience' features like an interface to supply a function to get missing keys. -2. The locking should be done only in the functions of the Cache struct. Else data races can occur or recursive locks are needed, which are both unwanted. -3. I prefer correct functionality over fast tests. It's ok for new tests to take seconds to proof something. - -#### Original Project - -TTLCache was forked from [wunderlist/ttlcache](https://github.com/wunderlist/ttlcache) to add extra functions not avaiable in the original scope. -The main differences are: - -1. A item can store any kind of object, previously, only strings could be saved -2. Optionally, you can add callbacks too: check if a value should expire, be notified if a value expires, and be notified when new values are added to the cache -3. The expiration can be either global or per item -4. Can exist items without expiration time -5. Expirations and callbacks are realtime. Don't have a pooling time to check anymore, now it's done with a heap. -- cgit v1.3