Data Cache

The Zend Data Cache component provides a set of PHP functions to improve performance by storing data in the cache.

The Zend Data Cache is used to cache different types of data (e.g., strings, arrays and objects), as well as script output or script output elements for various durations. Items can be stored in shared memory (SHM) or to disk. Namespaces are supported, to group cached objects for easy management.

Data Caching is primarily used when it is impractical or impossible to cache the entire page output, such as when sections of the script are fully dynamic, or when the conditions for caching the script are too numerous. An example of this kind of usage is when some of the output is a form: The data may include credit card numbers, addresses and other kinds of information that should not be cached, for security reasons.

How do I work with Data Cache?

Data Cache API

The Data Cache API includes the following functionality:

  • Storing variables to the cache
  • Fetching variables to the cache
  • Deleting variables from the cache
  • Clearing the cache
  • Disk/memory (SHM) storage
  • Caching using namespaces
  • Cache folder depth configuration

Note:

Zend Data Cache is disabled when running PHP in CLI mode.

Data Invalidation across Cluster nodes

Note:

This mechanism exists from Zend Server version 9.1 onward.

When you run Data Cache API functions to delete or clear cached objects and namespaces in a clustered environment, you only need to run a single API call, which will set the same call on all cluster nodes (as a centralized task). The following Data Cache API calls supports cluster wide operation:

  • zend_shm_cache_delete()
  • zend_disk_cache_delete()
  • zend_shm_cache_clear()
  • zend_disk_cache_clear()

Note:

By default, delete and clear API calls will be signaling all cluster nodes to invalidate the objects and namespaces. If for some reason, only local copy should be dropped, you can pass clusterDelete=true in the function parameters, so a cluster matching task to other nodes will not be created.