| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Codecov Report
@@ Coverage Diff @@
## master #3 +/- ##
=========================================
+ Coverage 76.05% 77.2% +1.14%
=========================================
Files 4 4
Lines 497 522 +25
=========================================
+ Hits 378 403 +25
Misses 65 65
Partials 54 54
Continue to review full report at Codecov.
|
Sorry, something went wrong.
|
Will it be better to filter keys outside fastcache? |
Sorry, something went wrong.
This won't be better, since returned keys for huge number of cached items (typical workload for fastcache) would require a lot of additional memory and pointers. |
Sorry, something went wrong.
| idx += keyLen | ||
| value := chunk[idx : idx+valLen] | ||
|
|
||
| if err := f(key, value); err != nil { |
There was a problem hiding this comment.
Currently it is called under per-bucket read lock. This means the bucket contents cannot be modified until all its entries are visited. This may take a lot of time for slow callbacks. I'm unsure whether this is OK.
Sorry, something went wrong.
There was a problem hiding this comment.
This also would lead to deadlock on an attempt to call Cache.Set(key, ...) inside f.
Sorry, something went wrong.
There was a problem hiding this comment.
If we mention these possible situations in the docs, do you think users will still ignore them and they will end up in undesired states?
Sorry, something went wrong.
There was a problem hiding this comment.
If we mention these possible situations in the docs, do you think users will still ignore them and they will end up in undesired states?
I'm absolutely sure :) There are the following choices:
I'm leaning to the last solution. Let's leave the PR open for a while.
Sorry, something went wrong.
There was a problem hiding this comment.
Could we push on a queue all operations (get, set, del...) while VisitAllEntries is working? And when it finishes, we run all the operations (in the same order, of course).
Sorry, something went wrong.
Retrieves cached keys by regex pattern.
|
Please don't put everything inside doc only. You can write the limitations, caveats and few basic complete examples on the readme.md Things to look out for should be most visible. There are a lot of nice features and TTL is definitely needed here. Please do make TTL ready at least as soon as possible. I think the format of method can be implemented and set, e.g. SetWithTTL(k,v,t) etc or just SetT(k,v,t) etc can be implemented already. No one will read the doc complete but at least they will definitely read the readme.md AND a wiki section will be nice with FAQs section |
Sorry, something went wrong.
|
some case TTL is must and cool, but some others cache had. fastcache is perfect in my trial project and running in product now. |
Sorry, something went wrong.
|
@andreiavrammsd do you need any help to finish this PR? fastcache is perfect for my use case, it's missing just the feature to iterate over all the entries. |
Sorry, something went wrong.
|
@diegobernardes, the PR is finished but not accepted because of performance concerns. Please see the discussions. |
Sorry, something went wrong.
|
Is there a feature for VisitAllEntries()? How can I code this / add to personal repo? |
Sorry, something went wrong.
|
Why not develop a function of simple Keys without regex pattern,I think there will be fewer performance problems 😄 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Iterate all entries in cache with a given callback with signature f func(k, v []byte) error. Iteration stops if error is returned from callback.
Outdated:
Retrieves cached keys by regex pattern.
type User struct { ID int `json:"id"` Username string `json:"username"` } const userCacheKey = "user:%d" cache := fastcache.New(1000) // Insert data into cache u := &User{ID: 1, Username: "John"} b, _ := json.Marshal(u) cache.Set([]byte(fmt.Sprintf(userCacheKey, u.ID)), b) u = &User{ID: 2, Username: "Doe"} b, _ = json.Marshal(u) cache.Set([]byte(fmt.Sprintf(userCacheKey, u.ID)), b) // Retrieve all users users, err := cache.Keys(`user:\d+`) if err != nil { panic(err) } fmt.Printf("Found %d user(s)\n", len(users)) for _, u := range users { user := &User{} if err := json.Unmarshal(cache.Get(nil, u), user); err != nil { fmt.Printf("Error retrieving key \"%s\"", u) continue } fmt.Printf("%#v\n", user) }