Beispiel #1
0
 /**
  * Support method for saveBulk() -- save a batch of records to the cache.
  *
  * @param Cache $recordCache    Cache service
  * @param array $cacheRecordIds Array of IDs in source|id format
  *
  * @return void
  */
 protected function cacheBatch(Cache $recordCache, array $cacheRecordIds)
 {
     if ($cacheRecordIds) {
         $recordLoader = $this->getController()->getServiceLocator()->get('VuFind\\RecordLoader');
         // Disable the cache so that we fetch latest versions, not cached ones:
         $recordLoader->setCacheContext(Cache::CONTEXT_DISABLED);
         $records = $recordLoader->loadBatch($cacheRecordIds);
         // Re-enable the cache so that we actually save the records:
         $recordLoader->setCacheContext(Cache::CONTEXT_FAVORITE);
         foreach ($records as $record) {
             $recordCache->createOrUpdate($record->getUniqueID(), $record->getSourceIdentifier(), $record->getRawData());
         }
     }
 }
Beispiel #2
0
 /**
  * Set the context to control cache behavior
  *
  * @param string $context Cache context
  *
  * @return void
  */
 public function setCacheContext($context)
 {
     if (null !== $this->recordCache) {
         $this->recordCache->setContext($context);
     }
 }