Expired data cache can be read by subsequent scripts for a time



When a data cache is created, an option exists to set the Time to Live (ttl), after which the data cache should no longer be available.  The first script to access the data cache after the ttl has passed will not find the data cache, but subsequent scripts will be able to access the cache for a while before the cache finally expires.


Zend Server 6 or higher.


This is by design. The cache will expire after an additional 120 seconds. There is a way to change this behavior, at a cost to performance. This is explained in the online documentation here:

Working with Data Cache

The section regarding Data Cache Lock-On-Expire explains it:

The Data Cache Lock-On-Expire feature reduces the load spike of a busy application by guaranteeing that an application gathers an expired piece from the data source only once, and by avoiding a situation where multiple PHP processes simultaneously detect that the data in the cache has expired, and repeatedly run high-cost operations.
How does it work?

When a stored Data Cache entry expires, the following process takes place:

  1. The first attempt to fetch it will receive a 'false' response.

  2. All subsequent requests will be receiving the expired object stored in the Data Cache for the duration of 120 seconds.

  3. During this time period, the php script that received the 'false' response generates an updated data entry and stores it in the Data Cache with the same key.

  4. As soon as the updated data entry is created, it is returned to the subsequent fetching requests.

  5. If this does not occur within the time period of 120 seconds, the entire process (1-4) will repeat itself.

This feature is controlled by directive zend_datacache.lock_on_expire in 'datacache.ini'.

The accepted values for this directive are 0 and 1, where:

1 = Enabled (default)

0 = Disabled.