aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/StudipCacheFactory.class.php
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2023-06-22 11:33:08 +0000
committerJan-Hendrik Willms <tleilax+studip@gmail.com>2023-06-22 11:33:08 +0000
commit9b9e88f7f692d7daf6c19deb2428431b15069604 (patch)
tree93e643f26cc9efb6bfb0b0eb3d4b2cd103fd033c /lib/classes/StudipCacheFactory.class.php
parent5da08f6c40f714fd37860f3ac19662888aa3780b (diff)
wrap any cache other than memory cache into a wrapper that caches the cache in memory, fixes #2202
Closes #2202 Merge request studip/studip!1782
Diffstat (limited to 'lib/classes/StudipCacheFactory.class.php')
-rw-r--r--lib/classes/StudipCacheFactory.class.php26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/classes/StudipCacheFactory.class.php b/lib/classes/StudipCacheFactory.class.php
index 5332e06..77c5973 100644
--- a/lib/classes/StudipCacheFactory.class.php
+++ b/lib/classes/StudipCacheFactory.class.php
@@ -54,11 +54,9 @@ class StudipCacheFactory
/**
- * @param Config an instance of class Config which will be used to
- * determine the class of the implementation of interface
- * StudipCache
- *
- * @return void
+ * @param Config $config an instance of class Config which will be used to
+ * determine the class of the implementation of interface
+ * StudipCache
*/
public static function setConfig($config)
{
@@ -68,8 +66,6 @@ class StudipCacheFactory
/**
* Resets the configuration and voids the cache instance.
- *
- * @return void
*/
public static function unconfigure()
{
@@ -174,18 +170,26 @@ class StudipCacheFactory
}
/**
- * Return an instance of a given class using some arguments
+ * Return an instance of a given class using some arguments. Unless the
+ * memory cache is instantiated, the cache will be wrapped in a wrapper
+ * class that uses a memory cache to reduce accesses to the cache.
*
- * @param string the name of the class
- * @param array an array of arguments to be used by the constructor
+ * @param string $class the name of the class
+ * @param array $arguments an array of arguments to be used by the constructor
*
* @return StudipCache an instance of the specified class
*/
public static function instantiateCache($class, $arguments)
{
$reflection_class = new ReflectionClass($class);
- return (is_array($arguments['config']) && count($arguments['config']) > 0)
+ $cache = (is_array($arguments['config']) && count($arguments['config']) > 0)
? $reflection_class->newInstanceArgs($arguments['config'])
: $reflection_class->newInstance();
+
+ if ($class !== StudipMemoryCache::class) {
+ return new StudipCacheWrapper($cache);
+ }
+
+ return $cache;
}
}