Cache lock refresh() for long-running operations #52778
Replies: 2 comments 12 replies
-
|
I agree. In the case of long-running operations that take an unpredictable amount of time to finish (e.g. making third-party API requests), the lack of a If the cache lock TTL can't be changed and the operation exceeds that time, race conditions can occur. Therefore, for any non-trivial, long-running operation, using the current cache lock implementation is risky. Further, the language in the Atomic Locks documentation is misleading in this case:
|
Beta Was this translation helpful? Give feedback.
-
|
Memcache does not allow extending TTL without resetting the key. So what you did in your code example is what symfony is doing behind the scenes. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
It would be nice to have a refresh() method on Cache lock instance, that would refresh lock TTL without releasing the lock. This would allow safe long-running operations without compromising with excessive TTL.
As an example such feature is implemented and documented in Symfony: https://symfony.com/doc/current/components/lock.html#expiring-locks .
Currently the closest workaround I found is this:
Having ->refresh(), same code could be simplified and made reliable:
Haven't found related issues, curious if this has been considered, is there known limitations to implementing this? Should be possible with Redis, probably utilizing transactions, but not sure about the other stores.
Thanks for checking!
Beta Was this translation helpful? Give feedback.
All reactions