Drupal Cache
- Caching is required to prevent dynamic websites numerous trips to the database to retrieve information about saved content, user, setting and config. Caching is used to speed up a website performance and visibility.
- Drupal uses its cache API to provide caching of modules, node and pages. The default table in which drupal stores the module settings is called ‘cache’. We can create our own cache tables for various modules. The only requisite of cache API for custom cache tables is that the structure must be identical to the default cache table.
- Besides cache table drupal also ships with three other cache tables know as
cache_page (stores cache of anonymous pages)
cache_menu (stores cache for navigational menus)
cache_filter ( stores cache copy of node’s content)
- The drupal_page_cache_header() prepares the cache data by setting HTTP headers.
- Functions of cache API
Three important cache functions:
cache_set($cid, $table=’cache’, $data, $expire=CACHE_PERMANENT, $header=NULL)
where , $cid= Unique cache ID
$table= Name of the cache table to store the data, by default ‘cache’ table is used.
$data= data to store in the cache.
$expire=The cache data expire time. You can use CACHE_PERMANENT, CACHE_TEMPORARY or a Unix Timestamp. By default CACHE_PERMANENT is set.
$headers= The HTTP header passed to the browser.
cache_get($cid, $table=‘cache’ )
where $cid= The cahe id of the data to retrieve.
$table= The table name from which data retrieved. The cache table is used by Default.
cache_clear_all($cid=NULL,$table=NULL,$wildcard=NULL)
where $cid=if set, clear only the given cache ID, otherwise delete all expire entries.
$table=the table to delete from.if not set entries from cache_block and cache_page table will be deleted.
$wildcard=if set to TRUE , all cache entries with ID contains a substring similar to $cid wil be deleted.
8yjebzxq9v