Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

(no description)

File Size: 272 lines (9 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

cache_handler:: (12 methods):
  __construct()
  get_item()
  get_items()
  has_item()
  clear()
  refresh()
  delete_item()
  delete_items()
  save()
  save_deferred()
  commit()
  assert_key_is_valid()


Class: cache_handler  - X-Ref

Class to handle and generates CacheItemPoolInterface objects.

This class will handle save, delete, cleanup etc. for the cache item.
For individual cache objects, this class will rely on {@cache_item} class.

__construct(string $module = 'repository')   X-Ref
Constructor for class cache_handler.
This class will accept the module which will determine the location of cached files.

param: string $module module string for cache directory.

get_item(string$key, ?int $ttl = null)   X-Ref
Returns a Cache Item representing the specified key.

This method must always return a CacheItemInterface object, even in case of
a cache miss. It MUST NOT return null.

param: string $key The key for which to return the corresponding Cache Item..
param: int|null $ttl Number of seconds for the cache item to live.
return: cache_item The corresponding Cache Item.

get_items(array $keys = [])   X-Ref
Returns a traversable set of cache items.

param: string[] $keys An indexed array of keys of items to retrieve.
return: iterable

has_item($key)   X-Ref
Confirms if the cache contains specified cache item.

Note: This method MAY avoid retrieving the cached value for performance reasons.
This could result in a race condition with CacheItemInterface::get(). To avoid
such situation use CacheItemInterface::isHit() instead.

param: string $key The key for which to check existence.
return: bool True if item exists in the cache, false otherwise.

clear()   X-Ref
Deletes all items in the pool.

return: bool True if the pool was successfully cleared. False if there was an error.

refresh(int $ttl)   X-Ref
Refreshes all items in the pool.

param: int $ttl Seconds to live.
return: void

delete_item(string $key)   X-Ref
Removes the item from the pool.

param: string $key The key to delete.
return: bool True if the item was successfully removed. False if there was an error.

delete_items(array $keys)   X-Ref
Removes multiple items from the pool.

param: string[] $keys An array of keys that should be removed from the pool.
return: bool  True if the items were successfully removed. False if there was an error.

save(cache_item $item)   X-Ref
Persists a cache item immediately.

param: cache_item $item The cache item to save.
return: bool True if the item was successfully persisted. False if there was an error.

save_deferred(cache_item $item)   X-Ref
Sets a cache item to be persisted later.

param: cache_item $item The cache item to save.
return: bool False if the item could not be queued or if a commit was attempted and failed. True otherwise.

commit()   X-Ref
Persists any deferred cache items.

return: bool True if all not-yet-saved items were successfully saved or there were none. False otherwise.

assert_key_is_valid(string $key)   X-Ref
Asserts that the given key is valid.
Some simple validation to make sure the passed key is a valid one.

param: string $key The key to validate.