/** * {@inheritdoc} */ public function onFieldDefinitionDelete(FieldDefinitionInterface $field_definition) { $entity_type_id = $field_definition->getTargetEntityTypeId(); $bundle = $field_definition->getTargetBundle(); $field_name = $field_definition->getName(); // Notify the storage about the field deletion. $this->entityTypeManager->getStorage($entity_type_id)->onFieldDefinitionDelete($field_definition); // Unset the bundle from the bundle field map key value collection. $bundle_field_map = $this->keyValueFactory->get('entity.definitions.bundle_field_map')->get($entity_type_id); unset($bundle_field_map[$field_name]['bundles'][$bundle]); if (empty($bundle_field_map[$field_name]['bundles'])) { // If there are no bundles left, remove the field from the map. unset($bundle_field_map[$field_name]); } $this->keyValueFactory->get('entity.definitions.bundle_field_map')->set($entity_type_id, $bundle_field_map); // Delete the cache entry. $this->cacheBackend->delete('entity_field_map'); // If the field map is initialized, update it as well, so that calls to it // do not have to rebuild it again. if ($field_map = $this->entityFieldManager->getFieldMap()) { unset($field_map[$entity_type_id][$field_name]['bundles'][$bundle]); if (empty($field_map[$entity_type_id][$field_name]['bundles'])) { unset($field_map[$entity_type_id][$field_name]); } $this->entityFieldManager->setFieldMap($field_map); } }
/** * Responds after a request has finished, but before it is sent to the client. * * @param \Guzzle\Common\Event $event * The Guzzle event object. */ public function onRequestSent(Event $event) { $request = $event['request']; $response = $event['response']; // Handle permanent redirects by setting the redirected URL so that the // client can grab it quickly. $redirect = FALSE; $url = $old_url = $request->getUrl(); if ($previous_response = $response->getPreviousResponse()) { if ($previous_response->getStatusCode() == 301 && ($location = $previous_response->getLocation())) { $response->getParams()->set('feeds.redirect', $location); $redirect = TRUE; $url = $request->getUrl(); } } $cache_hit = $response->getStatusCode() == 304; if ($redirect) { // Delete the old cache entry. $this->cacheBackend->delete($this->getCacheKey($old_url)); // Not sure if the repeated requests are smart enough to find the // redirect, so cache the old URL with the new response. static::$downloadCache[$old_url] = $response; } if ($redirect || !$cache_hit) { $cache = new \stdClass(); $cache->headers = array_change_key_case($response->getHeaders()->toArray()); // @todo We should only cache for certain status codes. $cache->code = $response->getStatusCode(); $this->cacheBackend->set($this->getCacheKey($url), $cache); } // Set in-page download cache. static::$downloadCache[$url] = $response; }
/** * {@inheritdoc} */ public function clear() { $this->reset(); if ($this->tags) { Cache::invalidateTags($this->tags); } else { $this->cache->delete($this->getCid()); } }
/** * {@inheritdoc} */ public function clear() { $this->reset(); if ($this->tags) { Cache::deleteTags($this->tags); } else { $this->cache->delete($this->cid); } }
/** * {@inheritdoc} */ public function clearCachedDefinitions() { if ($this->cacheBackend) { if ($this->cacheTags) { // Use the cache tags to clear the cache. Cache::invalidateTags($this->cacheTags); } else { $this->cacheBackend->delete($this->cacheKey); } } $this->definitions = NULL; }
/** * {@inheritdoc} */ public function rename($name, $new_name) { // If the cache was the first to be deleted, another process might start // rebuilding the cache before the storage is renamed. if ($this->storage->rename($name, $new_name)) { $this->cache->delete($this->getCacheKey($name)); $this->cache->delete($this->getCacheKey($new_name)); $this->findByPrefixCache = array(); return TRUE; } return FALSE; }
/** * Implements Drupal\Core\Config\StorageInterface::rename(). */ public function rename($name, $new_name) { // If the cache was the first to be deleted, another process might start // rebuilding the cache before the storage is renamed. if ($this->storage->rename($name, $new_name)) { $this->cache->delete($name); $this->cache->delete($new_name); Cache::deleteTags(array($this::FIND_BY_PREFIX_CACHE_TAG => TRUE)); $this->findByPrefixCache = array(); return TRUE; } return FALSE; }
/** * Submit handler that explicitly clears cache_example_files_count from cache. */ public function expireFiles($form, &$form_state) { // Clear cached data. This function will delete cached object from cache // bin. // // The first argument is cache id to be deleted. Since we've provided it // explicitly, it will be removed whether or not it has an associated // expiration time. The second argument (required here) is the cache bin. // Using cache_clear_all() explicitly in this way // forces removal of the cached item. $this->cacheBackend->delete('cache_example_files_count'); // Display message to the user. drupal_set_message($this->t('Cached data key "cache_example_files_count" was cleared.'), 'status'); }
/** * {@inheritdoc} */ public function resetImplementations() { $this->implementations = NULL; $this->hookInfo = NULL; $this->alterFunctions = NULL; // We maintain a persistent cache of hook implementations in addition to the // static cache to avoid looping through every module and every hook on each // request. Benchmarks show that the benefit of this caching outweighs the // additional database hit even when using the default database caching // backend and only a small number of modules are enabled. The cost of the // $this->cacheBackend->get() is more or less constant and reduced further // when non-database caching backends are used, so there will be more // significant gains when a large number of modules are installed or hooks // invoked, since this can quickly lead to // \Drupal::moduleHandler()->implementsHook() being called several thousand // times per request. $this->cacheBackend->set('module_implements', array()); $this->cacheBackend->delete('hook_info'); }
/** * {@inheritdoc} */ public function onFeedDeleteMultiple(array $feeds) { foreach ($feeds as $feed) { $this->cache->delete($this->getCacheKey($feed)); } }
/** * {@inheritdoc} */ protected function delete($name) { $this->cache->delete($name); unlink($this->fileStorage->getFilePath($name)); }
/** * Submit callback; clear CAPTCHA placement cache. * * @param array $form * Form structured array. * @param FormStateInterface $form_state * Form state structured array. */ public function clearCaptchaPlacementCacheSubmit(array $form, FormStateInterface $form_state) { $this->cacheBackend->delete('captcha_placement_map_cache'); drupal_set_message($this->t('Cleared the CAPTCHA placement cache.')); }
/** * {@inheritdoc} */ public function clearCache() { $this->map = NULL; $this->cache->delete('commerce_product.line_item_type_map'); }
/** * {@inheritdoc} */ public function delete($cid) { return $this->cacheBackend->delete($cid); }
/** * {@inheritdoc} */ public function clearCachedDefinitions() { $this->definitions = NULL; $this->schemaStorage->reset(); $this->cache->delete($this::CACHE_ID); }