当前位置: 首页>>代码示例>>PHP>>正文


PHP CacheBackendInterface::set方法代码示例

本文整理汇总了PHP中Drupal\Core\Cache\CacheBackendInterface::set方法的典型用法代码示例。如果您正苦于以下问题:PHP CacheBackendInterface::set方法的具体用法?PHP CacheBackendInterface::set怎么用?PHP CacheBackendInterface::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Cache\CacheBackendInterface的用法示例。


在下文中一共展示了CacheBackendInterface::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 protected function setUp()
 {
     parent::setUp();
     // Set up three memory backends to be used in the chain.
     $this->firstBackend = new MemoryBackend('foo');
     $this->secondBackend = new MemoryBackend('bar');
     $this->thirdBackend = new MemoryBackend('baz');
     // Set an initial fixed dataset for all testing. The next three data
     // collections will test two edge cases (last backend has the data, and
     // first backend has the data) and will test a normal use case (middle
     // backend has the data). We should have a complete unit test with those.
     // Note that in all cases, when the same key is set on more than one
     // backend, the values are voluntarily different, this ensures in which
     // backend we actually fetched the key when doing get calls.
     // Set a key present on all backends (for delete).
     $this->firstBackend->set('t123', 1231);
     $this->secondBackend->set('t123', 1232);
     $this->thirdBackend->set('t123', 1233);
     // Set a key present on the second and the third (for get), those two will
     // be different, this will ensure from where we get the key.
     $this->secondBackend->set('t23', 232);
     $this->thirdBackend->set('t23', 233);
     // Set a key on only the third, we will ensure propagation using this one.
     $this->thirdBackend->set('t3', 33);
     // Create the chain.
     $this->chain = new BackendChain('foobarbaz');
     $this->chain->appendBackend($this->firstBackend)->appendBackend($this->secondBackend)->appendBackend($this->thirdBackend);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:28,代码来源:BackendChainImplementationUnitTest.php

示例2: generate

 /**
  * {@inheritdoc}
  *
  * Cached by role, invalidated whenever permissions change.
  */
 public function generate(AccountInterface $account)
 {
     // User 1 is the super user, and can always access all permissions. Use a
     // different, unique identifier for the hash.
     if ($account->id() == 1) {
         return $this->hash('is-super-user');
     }
     $sorted_roles = $account->getRoles();
     sort($sorted_roles);
     $role_list = implode(',', $sorted_roles);
     $cid = "user_permissions_hash:{$role_list}";
     if ($static_cache = $this->static->get($cid)) {
         return $static_cache->data;
     } else {
         $tags = Cache::buildTags('config:user.role', $sorted_roles, '.');
         if ($cache = $this->cache->get($cid)) {
             $permissions_hash = $cache->data;
         } else {
             $permissions_hash = $this->doGenerate($sorted_roles);
             $this->cache->set($cid, $permissions_hash, Cache::PERMANENT, $tags);
         }
         $this->static->set($cid, $permissions_hash, Cache::PERMANENT, $tags);
     }
     return $permissions_hash;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:30,代码来源:PermissionsHashGenerator.php

示例3: user

 /**
  * User object.
  *
  * @return \Drupal\moodle\Sql\User
  */
 public function user()
 {
     // Static cache of already retrieved user data.
     $data =& drupal_static(__METHOD__, array());
     $user_cid = "moodle-user:{$this->user->id()}";
     // If we do not have this user id in the static cache, check {cache_data}.
     if (!isset($data[$user_cid])) {
         $cache = $this->cacheBackend->get($user_cid);
         if ($cache && $cache->data && isset($cache->data[$user_cid])) {
             $data[$user_cid] = $cache->data[$user_cid];
         }
     }
     // If nothing in the cache then retrieve it from the database.
     if (!isset($data[$user_cid])) {
         $user = new User();
         $this->query();
         $this->addFields();
         $statement = $this->query->execute();
         $statement->setFetchMode(\PDO::FETCH_INTO, $user);
         $data[$user_cid] = $statement->fetch();
         // Store the results for a day.
         $this->cacheBackend->set($user_cid, $data, REQUEST_TIME + 86400);
     }
     return $data[$user_cid];
 }
开发者ID:bonrita,项目名称:moodle,代码行数:30,代码来源:CurrentUser.php

示例4: generate

 /**
  * {@inheritdoc}
  *
  * Cached by role, invalidated whenever permissions change.
  */
 public function generate(AccountInterface $account)
 {
     $sorted_roles = $account->getRoles();
     sort($sorted_roles);
     $role_list = implode(',', $sorted_roles);
     if ($cache = $this->cache->get("user_permissions_hash:{$role_list}")) {
         $permissions_hash = $cache->data;
     } else {
         $permissions_hash = $this->doGenerate($sorted_roles);
         $this->cache->set("user_permissions_hash:{$role_list}", $permissions_hash, Cache::PERMANENT, array('user_role' => $sorted_roles));
     }
     return $permissions_hash;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:18,代码来源:PermissionsHash.php

示例5: loadBaseDefinitions

 /**
  * Loads the base country definitions.
  *
  * @return array
  */
 protected function loadBaseDefinitions()
 {
     if (!empty($this->baseDefinitions)) {
         return $this->baseDefinitions;
     }
     $cache_key = 'address.countries.base';
     if ($cached = $this->cache->get($cache_key)) {
         $this->baseDefinitions = $cached->data;
     } else {
         $this->baseDefinitions = json_decode(file_get_contents($this->definitionPath . 'base.json'), TRUE);
         $this->cache->set($cache_key, $this->baseDefinitions, CacheBackendInterface::CACHE_PERMANENT, ['countries']);
     }
     return $this->baseDefinitions;
 }
开发者ID:r-daneelolivaw,项目名称:chalk,代码行数:19,代码来源:CountryRepository.php

示例6: generate

 /**
  * {@inheritdoc}
  *
  * Cached by role, invalidated whenever permissions change.
  */
 public function generate(AccountInterface $account)
 {
     $sorted_roles = $account->getRoles();
     sort($sorted_roles);
     $role_list = implode(',', $sorted_roles);
     if ($cache = $this->cache->get("user_permissions_hash:{$role_list}")) {
         $permissions_hash = $cache->data;
     } else {
         $permissions_hash = $this->doGenerate($sorted_roles);
         $tags = Cache::buildTags('config:user.role', $sorted_roles, '.');
         $this->cache->set("user_permissions_hash:{$role_list}", $permissions_hash, Cache::PERMANENT, $tags);
     }
     return $permissions_hash;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:19,代码来源:PermissionsHashGenerator.php

示例7: setCachedDefinitions

 /**
  * Sets a cache of plugin definitions for the decorated discovery class.
  *
  * @param array $definitions
  *   List of definitions to store in cache.
  */
 protected function setCachedDefinitions($definitions)
 {
     if ($this->cacheBackend) {
         $this->cacheBackend->set($this->cacheKey, $definitions, Cache::PERMANENT, $this->cacheTags);
     }
     $this->definitions = $definitions;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:13,代码来源:DefaultPluginManager.php

示例8: getLineItemTypeId

 /**
  * {@inheritdoc}
  */
 public function getLineItemTypeId($product_type_id)
 {
     if (!isset($this->map)) {
         if ($cached_map = $this->cache->get('commerce_product.line_item_type_map')) {
             $this->map = $cached_map->data;
         } else {
             $this->map = $this->buildMap();
             $this->cache->set('commerce_product.line_item_type_map', $this->map);
         }
     }
     // A valid product type ID should always have a matching line item type ID.
     if (empty($this->map[$product_type_id])) {
         throw new \InvalidArgumentException(sprintf('No line item type found for the "%s" product type.', $product_type_id));
     }
     return $this->map[$product_type_id];
 }
开发者ID:alexburrows,项目名称:cream-2.x,代码行数:19,代码来源:LineItemTypeMap.php

示例9: onRequestSent

 /**
  * 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;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:39,代码来源:CachePlugin.php

示例10: testGetAllBundleInfo

 /**
  * Tests the getAllBundleInfo() method.
  *
  * @covers ::getAllBundleInfo
  */
 public function testGetAllBundleInfo()
 {
     $this->moduleHandler->invokeAll('entity_bundle_info')->willReturn([]);
     $this->moduleHandler->alter('entity_bundle_info', Argument::type('array'))->willReturn(NULL);
     $apple = $this->prophesize(EntityTypeInterface::class);
     $apple->getLabel()->willReturn('Apple');
     $apple->getBundleOf()->willReturn(NULL);
     $banana = $this->prophesize(EntityTypeInterface::class);
     $banana->getLabel()->willReturn('Banana');
     $banana->getBundleOf()->willReturn(NULL);
     $this->setUpEntityTypeDefinitions(['apple' => $apple, 'banana' => $banana]);
     $this->cacheBackend->get('entity_bundle_info:en')->willReturn(FALSE);
     $this->cacheBackend->set('entity_bundle_info:en', Argument::any(), Cache::PERMANENT, ['entity_types', 'entity_bundles'])->will(function () {
         $this->get('entity_bundle_info:en')->willReturn((object) ['data' => 'cached data'])->shouldBeCalled();
     })->shouldBeCalled();
     $this->cacheTagsInvalidator->invalidateTags(['entity_bundles'])->shouldBeCalled();
     $this->typedDataManager->clearCachedDefinitions()->shouldBeCalled();
     $expected = ['apple' => ['apple' => ['label' => 'Apple']], 'banana' => ['banana' => ['label' => 'Banana']]];
     $bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
     $this->assertSame($expected, $bundle_info);
     $bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
     $this->assertSame($expected, $bundle_info);
     $this->entityTypeBundleInfo->clearCachedBundles();
     $bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
     $this->assertSame('cached data', $bundle_info);
 }
开发者ID:vinodpanicker,项目名称:drupal-under-the-hood,代码行数:31,代码来源:EntityTypeBundleInfoTest.php

示例11: write

 /**
  * {@inheritdoc}
  */
 public function write($key, $content)
 {
     $this->storage()->save($key, $content);
     // Save the last mtime.
     $cid = 'twig:' . $key;
     $this->cache->set($cid, REQUEST_TIME);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:10,代码来源:TwigPhpStorageCache.php

示例12: generateFormatTagsSetting

 /**
  * Builds the "format_tags" configuration part of the CKEditor JS settings.
  *
  * @see getConfig()
  *
  * @param \Drupal\editor\Entity\Editor $editor
  *   A configured text editor object.
  *
  * @return array
  *   An array containing the "format_tags" configuration.
  */
 protected function generateFormatTagsSetting(Editor $editor)
 {
     // When no text format is associated yet, assume no tag is allowed.
     // @see \Drupal\Editor\EditorInterface::hasAssociatedFilterFormat()
     if (!$editor->hasAssociatedFilterFormat()) {
         return array();
     }
     $format = $editor->getFilterFormat();
     $cid = 'ckeditor_internal_format_tags:' . $format->id();
     if ($cached = $this->cache->get($cid)) {
         $format_tags = $cached->data;
     } else {
         // The <p> tag is always allowed — HTML without <p> tags is nonsensical.
         $format_tags = ['p'];
         // Given the list of possible format tags, automatically determine whether
         // the current text format allows this tag, and thus whether it should show
         // up in the "Format" dropdown.
         $possible_format_tags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'pre'];
         foreach ($possible_format_tags as $tag) {
             $input = '<' . $tag . '>TEST</' . $tag . '>';
             $output = trim(check_markup($input, $editor->id()));
             if ($input == $output) {
                 $format_tags[] = $tag;
             }
         }
         $format_tags = implode(';', $format_tags);
         // Cache the "format_tags" configuration. This cache item is infinitely
         // valid; it only changes whenever the text format is changed, hence it's
         // tagged with the text format's cache tag.
         $this->cache->set($cid, $format_tags, Cache::PERMANENT, $format->getCacheTags());
     }
     return $format_tags;
 }
开发者ID:dmyerson,项目名称:d8ecs,代码行数:44,代码来源:Internal.php

示例13: loadTreeData

 /**
  * {@inheritdoc}
  */
 public function loadTreeData($menu_name, MenuTreeParameters $parameters)
 {
     // Build the cache ID; sort 'expanded' and 'conditions' to prevent duplicate
     // cache items.
     sort($parameters->expandedParents);
     asort($parameters->conditions);
     $tree_cid = "tree-data:{$menu_name}:" . serialize($parameters);
     $cache = $this->menuCacheBackend->get($tree_cid);
     if ($cache && isset($cache->data)) {
         $data = $cache->data;
         // Cache the definitions in memory so they don't need to be loaded again.
         $this->definitions += $data['definitions'];
         unset($data['definitions']);
     } else {
         $links = $this->loadLinks($menu_name, $parameters);
         $data['tree'] = $this->doBuildTreeData($links, $parameters->activeTrail, $parameters->minDepth);
         $data['definitions'] = array();
         $data['route_names'] = $this->collectRoutesAndDefinitions($data['tree'], $data['definitions']);
         $this->menuCacheBackend->set($tree_cid, $data, Cache::PERMANENT, ['config:system.menu.' . $menu_name]);
         // The definitions were already added to $this->definitions in
         // $this->doBuildTreeData()
         unset($data['definitions']);
     }
     return $data;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:28,代码来源:MenuTreeStorage.php

示例14: getTestClasses

 /**
  * Discovers all available tests in all extensions.
  *
  * @param string $extension
  *   (optional) The name of an extension to limit discovery to; e.g., 'node'.
  *
  * @return array
  *   An array of tests keyed by the first @group specified in each test's
  *   PHPDoc comment block, and then keyed by class names. For example:
  *   @code
  *     $groups['block'] => array(
  *       'Drupal\block\Tests\BlockTest' => array(
  *         'name' => 'Drupal\block\Tests\BlockTest',
  *         'description' => 'Tests block UI CRUD functionality.',
  *         'group' => 'block',
  *       ),
  *     );
  *   @endcode
  *
  * @throws \ReflectionException
  *   If a discovered test class does not match the expected class name.
  *
  * @todo Remove singular grouping; retain list of groups in 'group' key.
  * @see https://www.drupal.org/node/2296615
  * @todo Add base class groups 'Kernel' + 'Web', complementing 'PHPUnit'.
  */
 public function getTestClasses($extension = NULL)
 {
     if (!isset($extension)) {
         if ($this->cacheBackend && ($cache = $this->cacheBackend->get('simpletest:discovery:classes'))) {
             return $cache->data;
         }
     }
     $list = array();
     $classmap = $this->findAllClassFiles($extension);
     // Prevent expensive class loader lookups for each reflected test class by
     // registering the complete classmap of test classes to the class loader.
     // This also ensures that test classes are loaded from the discovered
     // pathnames; a namespace/classname mismatch will throw an exception.
     $this->classLoader->addClassMap($classmap);
     foreach ($classmap as $classname => $pathname) {
         try {
             $class = new \ReflectionClass($classname);
         } catch (\ReflectionException $e) {
             // Re-throw with expected pathname.
             $message = $e->getMessage() . " in expected {$pathname}";
             throw new \ReflectionException($message, $e->getCode(), $e);
         }
         // Skip interfaces, abstract classes, and traits.
         if (!$class->isInstantiable()) {
             continue;
         }
         // Skip non-test classes.
         if (!$class->isSubclassOf('Drupal\\simpletest\\TestBase') && !$class->isSubclassOf('PHPUnit_Framework_TestCase')) {
             continue;
         }
         $info = static::getTestInfo($class);
         // Skip this test class if it requires unavailable modules.
         // @todo PHPUnit skips tests with unmet requirements when executing a test
         //   (instead of excluding them upfront). Refactor test runner to follow
         //   that approach.
         // @see https://www.drupal.org/node/1273478
         if (!empty($info['requires']['module'])) {
             if (array_diff($info['requires']['module'], $this->availableExtensions['module'])) {
                 continue;
             }
         }
         $list[$info['group']][$classname] = $info;
     }
     // Sort the groups and tests within the groups by name.
     uksort($list, 'strnatcasecmp');
     foreach ($list as &$tests) {
         uksort($tests, 'strnatcasecmp');
     }
     // Allow modules extending core tests to disable originals.
     \Drupal::moduleHandler()->alter('simpletest', $list);
     if (!isset($extension)) {
         if ($this->cacheBackend) {
             $this->cacheBackend->set('simpletest:discovery:classes', $list);
         }
     }
     return $list;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:83,代码来源:TestDiscovery.php

示例15: updateCompiledTemplate

 /**
  * Compile the source and write the compiled template to disk.
  */
 public function updateCompiledTemplate($cache_filename, $name)
 {
     $source = $this->loader->getSource($name);
     $compiled_source = $this->compileSource($source, $name);
     $this->storage()->save($cache_filename, $compiled_source);
     // Save the last modification time
     $cid = 'twig:' . $cache_filename;
     $this->cache_object->set($cid, REQUEST_TIME);
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:12,代码来源:TwigEnvironment.php


注:本文中的Drupal\Core\Cache\CacheBackendInterface::set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。