Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

Public Member Functions | Private Member Functions | Private Attributes | List of all members
eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache Class Reference

Simple internal In-Memory Cache Pool. More...

## Public Member Functions
| __construct (int $ttl=300, int $limit=100, bool $enabled=true)
| In Memory Cache constructor. More...
| setEnabled (bool $enabled=true)
| get (string $key)
| Returns a cache objects. More...
| setMulti (array $objects, callable $objectIndexes, string $listIndex=null)
| Set object in in-memory cache. More...
| deleteMulti (array $keys)
| Removes multiple in-memory cache from the pool. More...
| clear ()
| Deletes all cache in the in-memory pool. More...

## Private Member Functions
| vacuum ()
| Call to reduce cache items when $limit has been reached. More...

## Private Attributes
| $ttl
| $limit
| $enabled
| $cache = []
| $cacheExpiryTime = []
| $cacheAccessCount = []
| $cacheIndex = []

## Detailed Description

Simple internal In-Memory Cache Pool.

Only for use in ..\AbstractInMemoryHandler & ..\Adapter\TransactionalInMemoryCacheAdapter, may change depending on needs there.

Goal: By nature caches stale objects in memory to avoid round-trips to cache backend over network. Thus should only be used for meta data which changes in-frequently, and has limits and short expiry to keep the risk of using out-of-date data to a minimum. Besides backend round trips, also aims to keep memory usage to a minimum.

Properties:

- Limited by amount and time, to make sure to use minimal amount of memory, and reduce risk of stale cache.
- Secondary indexes, allows for populating memory quickly, and safely able to delete only knowing primary key E.g. I language object is loaded first by id, locale (eng-GB) lookup is also populated. Opposite is also true.
- On object limits, will first try to vacuum in-frequently used cache items, then by FIFO principle if needed.

Definition at line 27 of file InMemoryCache.php.

## Constructor & Destructor Documentation

## ◆ __construct()

eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache::__construct | ( | int | $ttl = `300`,
|  | int | $limit = `100`,
|  | bool | $enabled = `true`
| ) |  |

In Memory Cache constructor.

Parameters

  int | $ttl | Seconds for the cache to live, by default 300 milliseconds
  int | $limit | Limit for values to keep in cache, by default 100 cache values.
  bool | $enabled | For use by configuration to be able to disable or enable depending on needs.

Definition at line 65 of file InMemoryCache.php.

References eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache\$enabled, eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache\$limit, and eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache\$ttl.

## Member Function Documentation

## ◆ clear()

eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache::clear | ( |  | ) |

Deletes all cache in the in-memory pool.

Definition at line 179 of file InMemoryCache.php.

## ◆ deleteMulti()

eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache::deleteMulti | ( | array | $keys | ) |

Removes multiple in-memory cache from the pool.

Parameters

  string[] | $keys | An array of keys that should be removed from the pool.

Definition at line 159 of file InMemoryCache.php.

## ◆ get()

eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache::get | ( | string | $key | ) |

Returns a cache objects.

Parameters

  string | $key | Primary or secondary index to look for cache on.

Returns
  object|null Object if found, null if not.

Definition at line 92 of file InMemoryCache.php.

## ◆ setEnabled()

eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache::setEnabled | ( | bool | $enabled = `true` | ) |

Parameters

  bool | $enabled |

Returns
  bool Prior value

Definition at line 77 of file InMemoryCache.php.

References eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache\$enabled.

## ◆ setMulti()

eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache::setMulti | ( | array | $objects,
|  | callable | $objectIndexes,
|  | string | $listIndex = `null`
| ) |  |

Set object in in-memory cache.

Should only set Cache hits here!

Parameters

  object[] | $objects |
  callable | $objectIndexes | Return array of indexes per object (first argument), must return at least 1 primary index
  string | null | $listIndex | Optional index for list of items

Definition at line 117 of file InMemoryCache.php.

References eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache\$ttl, and eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache\vacuum().

## ◆ vacuum()

eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache::vacuum | ( |  | ) |
| private

Call to reduce cache items when $limit has been reached.

Deletes items using LFU approach where the least frequently used items are evicted from bottom and up. Within groups of cache used equal amount of times, the oldest keys will be deleted first (FIFO).

Definition at line 191 of file InMemoryCache.php.

Referenced by eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache\setMulti().

## Member Data Documentation

## ◆ $cache

eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache::$cache = []
| private

Definition at line 43 of file InMemoryCache.php.

## ◆ $cacheAccessCount

eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache::$cacheAccessCount = []
| private

Definition at line 49 of file InMemoryCache.php.

## ◆ $cacheExpiryTime

eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache::$cacheExpiryTime = []
| private

Definition at line 46 of file InMemoryCache.php.

## ◆ $cacheIndex

eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache::$cacheIndex = []
| private

Definition at line 56 of file InMemoryCache.php.

## ◆ $enabled

eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache::$enabled
| private

Definition at line 36 of file InMemoryCache.php.

Referenced by eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache\__construct(), and eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache\setEnabled().

## ◆ $limit

eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache::$limit
| private

Definition at line 33 of file InMemoryCache.php.

Referenced by eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache\__construct().

## ◆ $ttl

eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache::$ttl
| private

Definition at line 30 of file InMemoryCache.php.

Referenced by eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache\__construct(), and eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache\setMulti().

The documentation for this class was generated from the following file:

- InMemoryCache.php

Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.