protected CacheCollector::updateCache($lock = TRUE)
Writes a value to the persistent cache immediately.
Parameters
bool $lock: (optional) Whether to acquire a lock before writing to cache. Defaults to TRUE.
File
- core/lib/Drupal/Core/Cache/CacheCollector.php, line 218
Class
- CacheCollector
- Default implementation for CacheCollectorInterface.
Namespace
Drupal\Core\Cache
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | protected function updateCache( $lock = TRUE) { $data = array (); foreach ( $this ->keysToPersist as $offset => $persist ) { if ( $persist ) { $data [ $offset ] = $this ->storage[ $offset ]; } } if ( empty ( $data ) && empty ( $this ->keysToRemove)) { return ; } // Lock cache writes to help avoid stampedes. $cid = $this ->getCid(); $lock_name = $this ->normalizeLockName( $cid . ':' . __CLASS__ ); if (! $lock || $this ->lock->acquire( $lock_name )) { // Set and delete operations invalidate the cache item. Try to also load // an eventually invalidated cache entry, only update an invalidated cache // entry if the creation date did not change as this could result in an // inconsistent cache. if ( $cache = $this ->cache->get( $cid , $this ->cacheInvalidated)) { if ( $this ->cacheInvalidated && $cache ->created != $this ->cacheCreated) { // We have invalidated the cache in this request and got a different // cache entry. Do not attempt to overwrite data that might have been // changed in a different request. We'll let the cache rebuild in // later requests. $this ->cache-> delete ( $cid ); $this ->lock->release( $lock_name ); return ; } $data = array_merge ( $cache ->data, $data ); } // Remove keys marked for deletion. foreach ( $this ->keysToRemove as $delete_key ) { unset( $data [ $delete_key ]); } $this ->cache->set( $cid , $data , Cache::PERMANENT, $this ->tags); if ( $lock ) { $this ->lock->release( $lock_name ); } } $this ->keysToPersist = array (); $this ->keysToRemove = array (); } |
Please login to continue.