Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Drupal\Core\State uses a caching array for local caching of states. A cron running a queue is depending on this state being in sync. A second request could delete or set the state value and the queue is will still assume the old value in the static State cache.
Proposed resolution
In my opinion we should not be using a static cache for states since we depend on states being in sync between different requests or at the very least state cache should be optional. Maybe the caching part should be moved out of this class to the KeyValueStore. That way we can easily overwrite this behaviour
Comments
Comment #2
tim_djComment #3
tim_djComment #4
BerdirDrupal is full of static caching, there will always be issues with long-running processes with that, I'm not sure that can be adressed.
Static caching of state is pretty important because some keys are accessed *a lot* during a single request, that would result in many additional queries.
Comment #5
tim_djIn that case wouldn't it be convenient to be able to get an uncached state by adding an optional boolean to get() instead of calling resetCache() which would clear all cache? Or maybe an optional key to resetCache() so only that entry will be reset.
Comment #13
achapJust ran into this as well with queues and static cache with state api. Workaround for those who need it is to use the keyvalue factory service directly which is what the state api is built on top of and doesn't use a static cache. Agree with #5 that it would be good to have a way of busting the cache for a particular key using state.