-
Notifications
You must be signed in to change notification settings - Fork 499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added GetOrAdd to expirable LRU #155
base: main
Are you sure you want to change the base?
Conversation
+1, please merge. |
@dinghram |
@mgaffney Thanks for your response. From what I can tell, PeekOrAdd is a bit different. First, it does a "peek", which will not update the recentness of usage. Second, my GetOrAdd does an add-construct, where the passed in value is a function that will construct the new object if the object is not present. This is useful in my use case, where I am saving an object that has a sync.WaitGroup in it. The constructor-function I pass in creates the WaitGroup and adds 1 to it. The caller then waits for that group to be "done" if they didn't add the object. If they did add the object, they can fill out the cached object and then invoke "done" on the WaitGroup. This makes it possible to have many competing threads add a single object to the cache, and wait for one thread to fill it in, then they can all use it. I'd be happy to change my method name to "GetOrAddConstruct" or something. However, as my method is not doing a Peek, but rather a Get, I don't think I should change the name to "Peek...". Do you agree? |
Hi @dinghram, Yes, I can see that your type ConstructorFunc[V any] func() (V, error)
func (c *LRU[K, V]) GetOrAddFunc(key K, fn ConstructorFunc[V]) (value V, added bool, evicted bool, err error) { Thoughts? |
I agree. Changes are available now.
Thanks,
Don Inghram
…On Tue, Jan 16, 2024 at 2:09 PM Michael Gaffney ***@***.***> wrote:
Hi @dinghram <https://github.com/dinghram>,
Yes, I can see that your GetOrAdd is very different from PeekOrAdd. Given
that a constructor func might need to call a backend, can we change the
signature to allow an error to be returned from both the constructor and
the GetOrAdd method? Can we also rename the method to GetOrAddFunc since
it is so different? Here's what I was thinking:
type ConstructorFunc[V any] func() (V, error)
func (c *LRU[K, V]) GetOrAddFunc(key K, fn ConstructorFunc[V]) (value V, added bool, evicted bool, err error) {
Thoughts?
—
Reply to this email directly, view it on GitHub
<#155 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFQJ6OMCV76AG56UMJSOFGTYO3UB3AVCNFSM6AAAAAA335ZBUWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJUGUYTMOJWHE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I have no opinion on this, as I am no longer working on the downstream project. |
No description provided.