Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

(no description)

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

Defines 1 class

cache_test:: (72 methods):
  setUpBeforeClass()
  setUp()
  tearDownAfterClass()
  get_expected_application_cache_store()
  test_cache_config()
  test_windows_nasty_keys()
  test_set_identifiers()
  test_default_application_cache()
  test_default_session_cache()
  test_default_request_cache()
  test_on_cache_without_store()
  run_on_cache()
  test_definition_data_loader()
  test_definition_data_loader_versioned()
  test_definition_overridden_loader()
  test_definition_mappings_only()
  test_definition()
  test_definition_simplekeys()
  test_application_ttl_negative()
  test_application_ttl_positive()
  test_session_ttl_positive()
  test_application_manual_locking()
  test_application_event_invalidation()
  test_session_event_invalidation()
  test_application_definition_invalidation()
  test_session_definition_invalidation()
  test_distributed_application_event_invalidation()
  test_application_event_purge()
  test_session_event_purge()
  test_application_definition_purge()
  test_alt_cache_path()
  test_disable_stores()
  test_disable()
  test_multiple_application_loaders()
  ttl_or_not()
  ttl_and_static_acceleration_or_not()
  ttl_and_simple_data_or_not()
  create_versioned_cache()
  test_versioned_cache_basic()
  test_versioned_cache_objects()
  test_versioned_cache_not_exist()
  test_versioned_cache_incompatible_versioning()
  test_versioned_cache_single_copy()
  test_versioned_cache_outdated_local()
  test_versioned_cache_deleting_outdated()
  test_versioned_cache_static()
  test_versioned_cache_3_layers_basic()
  test_versioned_cache_3_layers_different_data()
  test_multiple_session_loaders()
  test_session_cache_switch_user()
  test_session_cache_switch_user_application_mapping()
  test_dual_session_caches()
  test_session_cache_switch_user_multiple()
  test_application_locking()
  test_application_locking_multiple_identifier_cache()
  test_application_locking_before_write()
  test_application_conflicting_locks()
  test_application_locking_multiple_layers()
  test_application_locking_multiple_layers_failures()
  test_purge_stores_used_by_definition()
  test_purge_routines()
  test_purge_all_with_adhoc_caches()
  test_defaults_support_searching()
  test_static_acceleration()
  test_identifiers_have_separate_caches()
  test_performance_debug()
  static_acceleration_performance_provider()
  test_static_acceleration_values_performance()
  test_static_cache()
  test_performance_debug_off()
  test_session_event_purge_same_second()
  test_session_distinct_storage_key()


Class: cache_test  - X-Ref

PHPunit tests for the cache API

This file is part of Moodle's cache API, affectionately called MUC.
It contains the components that are requried in order to use caching.

setUpBeforeClass()   X-Ref
Load required libraries and fixtures.


setUp()   X-Ref
Set things back to the default before each test.


tearDownAfterClass()   X-Ref
Final task is to reset the cache system


get_expected_application_cache_store()   X-Ref
Returns the expected application cache store.

return: string

test_cache_config()   X-Ref
Tests cache configuration


test_windows_nasty_keys()   X-Ref
Tests for cache keys that would break on windows.


test_set_identifiers()   X-Ref
Tests set_identifiers fails post cache creation.

set_identifiers cannot be called after initial cache instantiation, as you need to create a difference cache.

test_default_application_cache()   X-Ref
Tests the default application cache


test_default_session_cache()   X-Ref
Tests the default session cache


test_default_request_cache()   X-Ref
Tests the default request cache


test_on_cache_without_store()   X-Ref
Tests using a cache system when there are no stores available (who knows what the admin did to achieve this).


run_on_cache(cache_loader $cache)   X-Ref
Runs a standard series of access and use tests on a cache instance.

This function is great because we can use it to ensure all of the loaders perform exactly the same way.

param: cache_loader $cache

test_definition_data_loader()   X-Ref
Tests a definition using a data loader


test_definition_data_loader_versioned()   X-Ref
Tests a definition using a data loader with versioned keys.


test_definition_overridden_loader()   X-Ref
Tests a definition using an overridden loader


test_definition_mappings_only()   X-Ref
Test the mappingsonly setting.


test_definition()   X-Ref
Test a very basic definition.


test_definition_simplekeys()   X-Ref
Test a definition using the simple keys.


test_application_ttl_negative()   X-Ref
Test a negative TTL on an application cache.


test_application_ttl_positive()   X-Ref
Test a positive TTL on an application cache.


test_session_ttl_positive()   X-Ref
Test a negative TTL on an session cache.


test_application_manual_locking()   X-Ref
Tests manual locking operations on an application cache


test_application_event_invalidation()   X-Ref
Tests application cache event invalidation


test_session_event_invalidation()   X-Ref
Tests session cache event invalidation


test_application_definition_invalidation()   X-Ref
Tests application cache definition invalidation


test_session_definition_invalidation()   X-Ref
Tests session cache definition invalidation


test_distributed_application_event_invalidation()   X-Ref
Tests application cache event invalidation over a distributed setup.


test_application_event_purge()   X-Ref
Tests application cache event purge


test_session_event_purge()   X-Ref
Tests session cache event purge


test_application_definition_purge()   X-Ref
Tests application cache definition purge


test_alt_cache_path()   X-Ref
Test the use of an alt path.
If we can generate a config instance we are done :)


test_disable_stores()   X-Ref
Test disabling the cache stores.


test_disable()   X-Ref
Test disabling the cache.


test_multiple_application_loaders()   X-Ref
Test that multiple application loaders work ok.


ttl_or_not()   X-Ref
Data provider to try using a TTL or non-TTL cache.

return: array

ttl_and_static_acceleration_or_not()   X-Ref
Data provider to try using a TTL or non-TTL cache, and static acceleration or not.

return: array

ttl_and_simple_data_or_not()   X-Ref
Data provider to try using a TTL or non-TTL cache, and simple data on or off.

return: array

create_versioned_cache(bool $ttl, bool $threelayer = false,bool $staticacceleration = false, bool $simpledata = false)   X-Ref
Shared code to set up a two or three-layer versioned cache for testing.

param: bool $ttl If true, sets TTL in the definition
param: bool $threelayer If true, uses a 3-layer instead of 2-layer cache
param: bool $staticacceleration If true, enables static acceleration
param: bool $simpledata If true, enables simple data
return: \cache_application Cache

test_versioned_cache_basic(bool $ttl, bool $simpledata)   X-Ref
Tests basic use of versioned cache.

param: bool $ttl If true, uses a TTL cache.
param: bool $simpledata If true, turns on simple data flag

test_versioned_cache_objects(bool $ttl, bool $staticacceleration)   X-Ref
Tests versioned cache with objects.

param: bool $ttl If true, uses a TTL cache.
param: bool $staticacceleration If true, enables static acceleration

test_versioned_cache_not_exist(bool $ttl)   X-Ref
Tests requesting a version that doesn't exist.

param: bool $ttl If true, uses a TTL cache.

test_versioned_cache_incompatible_versioning(bool $ttl)   X-Ref
Tests attempts to use get after set_version or get_version after set.

param: bool $ttl If true, uses a TTL cache.

test_versioned_cache_single_copy(bool $ttl)   X-Ref
Versions are only stored once, so if you set a newer version you will always get it even
if you ask for the lower version number.

param: bool $ttl If true, uses a TTL cache.

test_versioned_cache_outdated_local(bool $ttl)   X-Ref
If the first (local) store has an outdated copy but the second (shared) store has a newer
one, then it should automatically be retrieved.

param: bool $ttl If true, uses a TTL cache.

test_versioned_cache_deleting_outdated(bool $ttl)   X-Ref
When we request a newer version, older ones are automatically deleted in every level of the
cache (to save I/O if there are multiple requests, as if there is another request it will
not have to retrieve the values to find out that they're old).

param: bool $ttl If true, uses a TTL cache.

test_versioned_cache_static()   X-Ref
Tests a versioned cache when using static cache.


test_versioned_cache_3_layers_basic()   X-Ref
Tests basic use of 3-layer versioned caches.


test_versioned_cache_3_layers_different_data()   X-Ref
Tests use of 3-layer versioned caches where the 3 layers currently have different versions.


test_multiple_session_loaders()   X-Ref
Test that multiple application loaders work ok.


test_session_cache_switch_user()   X-Ref
Test switching users with session caches.


test_session_cache_switch_user_application_mapping()   X-Ref
Test switching users with session caches.


test_dual_session_caches()   X-Ref
Test two session caches being used at once to confirm collisions don't occur.


test_session_cache_switch_user_multiple()   X-Ref
Test multiple session caches when switching user.


test_application_locking()   X-Ref
Test application locking.


test_application_locking_multiple_identifier_cache()   X-Ref
The application locking feature should work with caches that support multiple identifiers
(static cache and MongoDB with a specific setting).


test_application_locking_before_write()   X-Ref
Test requiring a lock before attempting to set a key.


test_application_conflicting_locks()   X-Ref
Test that invalid lock setting combinations are caught.


test_application_locking_multiple_layers()   X-Ref
Test that locking before write works when writing across multiple layers.

return: void

test_application_locking_multiple_layers_failures()   X-Ref
Tests that locking fails correctly when either layer of a 2-layer cache has a lock already.


test_purge_stores_used_by_definition()   X-Ref
Test the static cache_helper method purge_stores_used_by_definition.


test_purge_routines()   X-Ref
Test purge routines.


test_purge_all_with_adhoc_caches()   X-Ref
Tests that ad-hoc caches are correctly purged with a purge_all call.


test_defaults_support_searching()   X-Ref
Test that the default stores all support searching.


test_static_acceleration()   X-Ref
Test static acceleration

Note: All the assertGreaterThanOrEqual() in this test should be assertGreaterThan() be because of some microtime()
resolution problems under some OSs / PHP versions, we are accepting equal as valid outcome. For more info see MDL-57147.

test_identifiers_have_separate_caches()   X-Ref
No description

test_performance_debug()   X-Ref
No description

static_acceleration_performance_provider()   X-Ref
Data provider for static acceleration performance tests.

return: array

test_static_acceleration_values_performance($value,array $firstfetchstats,array $secondfetchstats)   X-Ref
Test performance of static acceleration caches with values which are frequently confused with missing values.

param: mixed $value The value to test
param: array $firstfetchstats The expected stats on the first fetch
param: array $secondfetchstats The expected stats on the subsequent fetch

test_static_cache()   X-Ref
No description

test_performance_debug_off()   X-Ref
No description

test_session_event_purge_same_second()   X-Ref
Tests session cache event purge and subsequent visit in the same request.

This test simulates a cache being created, a value being set, then the value being purged.
A subsequent use of the same cache is started in the same request which fills the cache.
A new request is started a short time later.
The cache should be filled.

test_session_distinct_storage_key()   X-Ref
Test that values set in different sessions are stored with different key prefixes.