- Issue created by @aiglesiasn
- last update
over 1 year ago 37 pass, 3 fail - @aiglesiasn opened merge request.
- Status changed to Needs work
over 1 year ago 10:36pm 30 May 2023 - πΊπΈUnited States mrweiner
Chatting on slack but adding some notes in here just for future reference.
/**
* @var object
*/
protected $staticTagsCache;We don't want to keep this "temp" cache on the slot object, because the same data needs to be accessible from every slot instance with the same ID. As in
$slot_1 = $manager->openSlot('my_module', 'some_api', 'id'); $slot_2 = $manager->openSlot('my_module', 'some_api', 'id'); $slot_1->setCache('some_data'); $slot_1->getCacheData == $slot_2->getCacheData(); // <-- this needs to be true, but will not be if you're returning data from a property on a specific slot.
$this->staticTagsCache = &drupal_static(__FUNCTION__);
This is problematic for a similar reason. Magic
__FUNCTION__
is scoped to the class instance, and not the cache ID. We'd need to do like&drupal_static($cache_id);
to ensure that the data is associated with the proper cache entry and not the name of the doSetCache function.if (empty($this->staticTagsCache)) { $this->staticTagsCache = (object) [ 'id' => $this->id, 'data' => $data, 'expire' => $expire, 'tags' => $tags]; }
We don't want to check whether it's empty. This should just mimic the regular setter in this method, setting the static value with the same data as the cache entry. We also need to make sure that the static variable is set such that it has the same properties as on $this->getCache() (data on the data property, etc). It needs to mimic a cache entry.
$cache_item = $this->cache->get($this->id, $allow_invalid); if (!$cache_item) { if (!empty($this->staticTagsCache)) { $cache_item = $this->staticTagsCache; } } return $cache_item ?: NULL;
If we always set a value in doSetCache, then these conditionals need to be handled differently, so something like.
$static_cached = drupal_static($this->id); $cache_item = $this->cache->get($this->id, $allow_invalid); return $static_cached ?: $cache_item ?: NULL;
Only snag is $allow_invalid -- I don't know how this would be handled by the static implementation.
- Status changed to Closed: duplicate
over 1 year ago 7:19pm 31 May 2023 - πΊπΈUnited States mrweiner
@aiglesiasn closing this as a duplicate. I've made some progress on this in the other ticket.