52 Commits

Author SHA1 Message Date
sam marshall
0f8577784d MDL-78467 core_cache: Improve cache locking API
* Makes it possible to safely call acquire_lock so that it throws an
  exception instead of returning false if it can't get a lock (which
  most existing uses assumed it already does).
* Fix some omissions from the requirelockingbeforewrite option (it
  now checks on delete).
* Modinfo uses a versioned cache, so it is not necessary to delete
  items, only increase the version. (Provided we keep track of
  cacherev carefully...)
2023-09-14 09:28:10 +01:00
sam marshall
8a0f706033 MDL-72837 core_cache: Add versioned cache support
Adds new set_versioned and get_versioned APIs to cache, which means you can
request a specific version from cache and it will not return an outdated
version.

This is important when using multi-layer-caches where a local cache might have
an outdated version of the cache, but the shared cache has a current version.
With this feature, the content of the cache does not have to be rebuilt, as
it will automatically retrieve it from the shared cache if necessary.
2022-02-23 16:58:38 +00:00
Eloy Lafuente (stronk7)
3a5641cb74 MDL-67673 phpunit: Remove deprecated assertEquals() params
The optional parameters of assertEquals() and assertNotEquals()
are deprecated in PHPUnit 8 (to be removed in PHPUnit 9):

- delta => use assertEqualsWithDelta()
- canonicalize => use assertEqualsCanonicalizing()
- ignoreCase => use assertEqualsIgnoringCase
- maxDepth => removed without replacement.

More info @ https://github.com/sebastianbergmann/phpunit/issues/3341

Initial search done with:

ag 'assert(Not)?Equals\(.*,.*,' --php

Then, running tests and fixing remaining cases.
2020-10-21 12:46:00 +02:00
Eloy Lafuente (stronk7)
f94195c320 MDL-67673 phpunit: Remove deprecated assertInternalType()
While this is not strictly required, because removal will
happen in PHPUnit 9.0, we are already getting rid of all
uses in core.

From release notes:https://phpunit.de/announcements/phpunit-8.html

assertInternalType() is deprecated and will be removed in
PHPUnit 9. Refactor your test to use assertIsArray(), assertIsBool(),
assertIsFloat(), assertIsInt(), assertIsNumeric(), assertIsObject(),
assertIsResource(), assertIsString(), assertIsScalar(),
assertIsCallable(), or assertIsIterable() instead.
2020-10-21 12:45:59 +02:00
Eloy Lafuente (stronk7)
f6711bb394 MDL-67673 phpunit: Fix the return type of template methods
All the setup/teardown/pre/post/conditions template methods
now are required to return void. This was warned with phpunit 7
and now is enforced.

At the same time, fix a few wrong function names,
provider data and param types, return statements...
2020-10-21 12:45:59 +02:00
David Mudrák
ea43f6c1c8 MDL-64452 cache: Add tests for key prefix based on session id
Unfortunately, we can't simply use session_id() to regenerate the
session id in unit tests. Starting from PHP 7.2, it would trigger
"session_id(): Cannot change session id when headers already sent",
refer to MDL-60978 and PHP bug #75628 for more details.

As a workaround, we use a static property allowing us to inject the
value that we then use as a session identifier. This is reasonably
enough to make sure that the identifier is used as a part of the key
prefix.
2019-02-15 09:36:43 +01:00
Andrew Nicols
0a197875df MDL-63101 cache: Improve accuracy of cache event invalidation 2018-08-27 14:43:42 +08:00
Eloy Lafuente (stronk7)
4d505af519 Merge branch 'MDL-55267-master-deprecation' of https://github.com/marcusgreen/moodle 2017-03-21 10:18:56 +01:00
Rajesh Taneja
dba39da081 MDL-58169 phpunit: Clear opcode cache before checking file
In unit test, we write cache file often and
opcache might fail to detect changes. It will
be nice to invalidate opcode cache to ensure
we have the correct file_exists status
2017-03-14 13:30:24 +08:00
Marcus Green
f2894f322d MDL-55267 cache: Remove deprecated field datasourceaggregate 2017-03-13 16:31:45 +00:00
Andrew Nicols
8fa816e0b0 Merge branch 'wip-mdl-56273' of https://github.com/rajeshtaneja/moodle 2016-11-02 14:30:08 +08:00
Rajesh Taneja
4a910b9aa6
MDL-56273 cache: Fixed initialise call
After store is created, it should be checked if
it's ready before calling initialise
2016-11-02 14:26:50 +08:00
Andrew Nicols
c6ae02c184 Merge branch 'MDL-48468' of https://github.com/mr-russ/moodle 2016-11-02 10:13:42 +08:00
Russell Smith
a330e83ade MDL-56273 cache: Use is_ready() to determine if cache is really ready. 2016-10-31 19:44:05 +11:00
Russell Smith
a169739d5d MDL-56273 cache: Use cache initialise always.
purge_all() and purge_by_definition() look in the configuration
for which caches are available and then creates them to purge them.
The configuration stores the values used by initialise(), not
initialise_unit_test_instance() and would therefore fail to purge
all caches if they were not purged by another means.

In the case of filestore, it's purged by unit tests, in the case
of memcache(d), it purges the whole store when a single definition
is requested.

Therefore all configuration was moved into the configuration file
during unit tests and does not have any special override codes in
the unit test infrastructure.
2016-10-30 13:42:43 +11:00
Russell Smith
68b1e13094 MDL-48468 cache: Import Redis cachestore
This code was originally taken from; https://github.com/durana/moodle-cachestore_redis
Special thanks to Mark Nielsen and Adam Durana for their work on this.

Since the original import;
- Mode session support has been added.
- Some cleanup of names has been made.
- Data guarantee and references support was added.
2016-10-30 13:34:43 +11:00
David Monllao
ab9ca549e7 Merge branch 'wip-mdl-56347' of https://github.com/rajeshtaneja/moodle 2016-10-25 15:20:06 +08:00
Russell Smith
ae9e735c77
MDL-56347 caching: Better class variables for notices. 2016-10-21 09:21:11 +08:00
Rajesh Taneja
502b66f53d
MDL-56347 phpunit: Set class for alternative cache store
If alternative cache store is sued, then set the class
and warn user about this.
2016-10-21 09:20:37 +08:00
Russell Smith
ec4b83b92a MDL-55922 cache: Improve static cache performance
Static cache has a very flexible storage capability
and does not need all the checks performed on it.
Enabling dereferencing handling and multiple identifiers
removes a lot of unneeded overhead for request caches that
have many get calls.

The changes were modelled on the static acceleration changes
done in MDL-53208.
2016-09-12 11:58:55 +10:00
Russell Smith
7ff43e1acf MDL-55604 cache: Fix identifier and cacheable_object
When a cachable object is store in the static cache from
the backing store, it was incorrect serialised rather than
using the wake function.  This has been resolved and tests added.

During the investigation into cacheable_object, it was discovered
that set_identifiers never removes identifiers when you call it,
so set_identifiers(array('a')) and set_identifiers(array('b')) really
resulted in array('a','b') as the identifiers rather than 'b'.

The fix for this issue depends on the set_identifiers fix and
they have been coupled together as a result.
2016-08-24 11:26:20 +10:00
Jun Pataleta
d6806d8eaf MDL-54984 cache: Added todo tags to items for 3.3 deprecations 2016-07-26 00:46:46 +08:00
Russell Smith
98d580888b MDL-53208 caching: parse_key not required for static cache.
static cache operates on a single cache instance, it can't share
with others and can use the supplied key immediately.
2016-02-28 17:01:50 +11:00
Eloy Lafuente (stronk7)
093c161d46 Merge branch '45699-29' of git://github.com/samhemelryk/moodle
Conflicts:
	cache/upgrade.txt
2014-12-23 02:01:36 +01:00
Sam Hemelryk
63b159d0d4 MDL-48568 cache: stores now determine testing
Cache stores are now responsible for deciding if they are suitable
for use as the primary cache store during unit and acceptance tests

Changes are as follows:
* New method: cache_store::ready_to_be_used_for_testing
* Core cache store have been updated to override this method as
  required.
* MongoDB usesafe default changed to true to match actual default
  behaviour.
2014-12-12 09:30:46 +13:00
Sam Hemelryk
427c41ef2d MDL-45699 cache: renamed cache_config_phpunittest
Renamed cache_config_phpunittest to cache_config_testing
2014-12-09 10:51:38 +13:00
Sam Hemelryk
45a8db7f7b MDL-45699 cache: acceptance test improvements
We now use the unit test cache config class when running
acceptance tests so that the same defines are applicable there.
2014-12-09 10:51:34 +13:00
Sam Hemelryk
c1fb8f6d2e MDL-46151 cachestore_memcache: now checks extension version for support 2014-10-14 08:27:45 +13:00
Sam Hemelryk
c9ef35e1f3 MDL-46208 cachestore_mongo: fixed invalid collection name use 2014-07-04 08:11:27 +12:00
Sam Hemelryk
eefb680d8e MDL-45513 cache: implemented defines for unit testing alternative caches 2014-05-30 08:41:07 +12:00
Sam Hemelryk
79a8ea653c MDL-45513 cache: added support to unit tests for alt cache stores 2014-05-30 08:41:07 +12:00
Sam Hemelryk
b51fed38f2 MDL-40903 cache: renamed loader method to reflect static accelerator 2013-09-25 09:05:18 +12:00
Sam Hemelryk
d074fb091d MDL-40903 cache: renamed persistcache to staticacceleration 2013-09-25 09:05:18 +12:00
Marina Glancy
d67a1a8815 MDL-40903 cache: Unittests and small fixes for persistent application cache 2013-09-25 09:04:36 +12:00
Sam Hemelryk
8bc1d659b8 MDL-40903 cache: coding style tidyup pre-integration 2013-09-25 09:04:35 +12:00
Sam Hemelryk
083fa87759 MDL-40903 cache: converted persistent into persistentdata
At the same time all cache instances were made persistent
2013-09-25 09:04:35 +12:00
Sam Hemelryk
85008bedd5 MDL-41106 cache: several fixes for the session cache.
This issue makes several fixes for the session loader and the session store.
 * maxsize argument now works for session caches.
 * fixed performance hole when interation occurs frequently.
 * fixed cache purge bug occuring when multiple caches are defined before being used.
 * improved lastaccess handling.

Big thanks to Marina who contributed the following commits:
 * Always make sure the elements in cache are sorted so we need to remove only elements in the beginning of array
 * Remove expired elements from session store to free memory
 * Minor bug fixes
2013-08-26 09:15:57 +12:00
Damyon Wiese
5ebe37fb27 Revert "MDL-41106 cache: several fixes for the session cache."
This reverts commit 89182546a0ae93a2aef79383bac902c77c7801f8.
This reverts commit 170b05362a82b2c1f5353551b7bd6fe4246fe951.
This reverts commit 2e9d5a534e8e3045923055baa1609d66cec0affe.
2013-08-19 15:32:08 +08:00
Sam Hemelryk
89182546a0 MDL-41106 cache: tidied up several elements 2013-08-19 11:32:08 +12:00
Sam Hemelryk
923f1c420c MDL-40700 cache: fixed cache store unit tests 2013-07-22 10:40:45 +12:00
Sam Hemelryk
4a749e93b4 MDL-40555 cache: implemented unit tests for default search functionality 2013-07-16 08:29:17 +08:00
Sam Hemelryk
46e17f04c7 MDL-37500 cache: implemented sharing options and gui 2013-05-07 11:57:37 +12:00
Sam Hemelryk
dbd2ea4e1f MDL-38565 cache: session caches now function as expected
This change is a large change to the way sessions are handled
within MUC after it was discovered that session did not function
as expected when any store other than the default session store
was being used.
As part of this change the session loader has been largely
customised in order to consolidate session data for the loader.
The unit tests have also being greatly increased to provide
better coverage for sessions.
2013-04-19 10:11:48 +12:00
Eloy Lafuente (stronk7)
caa5bcea00 Merge branch 'wip-MDL-38247-m25' of git://github.com/samhemelryk/moodle 2013-03-05 01:08:23 +01:00
Sam Hemelryk
0323e1ab99 MDL-38165 cache: added unit tests for event purging of persistent caches 2013-03-01 11:38:02 +13:00
Sam Hemelryk
ac6754a679 MDL-38427 cache: implemented unit tests for all core cache stores 2013-03-01 10:11:55 +13:00
Sam Hemelryk
e0d9b7c0d4 MDL-37683 cache: siteidentifier is now included in the keys 2013-02-18 08:32:03 +13:00
Sam Hemelryk
956d3544f0 MDL-36363 cache: added unit tests for muliple loaders 2013-01-31 12:16:08 +13:00
Sam Hemelryk
94ef67cf5f MDL-36466 cache: tidy up after review 2012-11-26 08:12:00 +13:00
Sam Hemelryk
82afd05c35 MDL-36466 cache: renamed disable to disable_stores and added tests 2012-11-26 08:12:00 +13:00