Example: Cache API

Same name in other branches
  1. 3.x modules/cache_example/cache_example.module \cache_example
  2. 7.x-1.x cache_example/cache_example.module \cache_example

Demonstrates how a module can use the Cache API.

Cache API allows us to cache data that is heavy to calculate. As this can significantly speed up the Drupal site, it is recommended to use cache mechanism when it is appropriate.

Cache in Drupal is very easy to use. This example will search entire Drupal folder and display all files. Since this operation includes filesystem it can take a while. This list will not change much on production websites, so we decide to cache it.

See also

\Drupal\Core\Cache\CacheBackendInterface

Parent topics

File

modules/cache_example/cache_example.module, line 8

Classes

Title Sort descending File name Summary
CacheExampleTest modules/cache_example/tests/src/Functional/CacheExampleTest.php Tests for the cache_example module.