diff options
| author | Jan-Hendrik Willms <tleilax+github@gmail.com> | 2021-07-22 16:07:19 +0200 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+github@gmail.com> | 2021-07-22 16:19:12 +0200 |
| commit | a3da1483a9e689846179159355badfec8073dbec (patch) | |
| tree | 770dcca6bdf5f6f2a11b0e7fcbbeda6919a3fc52 /lib/models/StudipCacheOperation.php | |
current code from svn, revision 62608
Diffstat (limited to 'lib/models/StudipCacheOperation.php')
| -rw-r--r-- | lib/models/StudipCacheOperation.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/models/StudipCacheOperation.php b/lib/models/StudipCacheOperation.php new file mode 100644 index 0000000..938a75a --- /dev/null +++ b/lib/models/StudipCacheOperation.php @@ -0,0 +1,46 @@ +<?php +/** + * Model for a stored cache operation. + * + * This model represents a stored cache operation when the used cache object + * was proxied. This occurs when the configured cache object failed to load + * correctly or when the configured cache cannot be used in the respective + * environment. In CLI mode, some caches may not be used since the + * surrounding web server component is missing. + * + * @author Jan-Hendrik Willms <tleilax+studip@gmail.com> + * @license GPL2 or any later version + * @since Stud.IP 3.3 + */ +class StudipCacheOperation extends SimpleORMap +{ + /** + * Configures the model. + * + * @param Array $config The config settings + */ + public static function configure($config = []) + { + $config['db_table'] = 'cache_operations'; + + parent::configure($config); + } + + /** + * Applies any pending cache operation to the passed cache object. + * The operations are applied in chronological order and are deleted + * from the database after they have been applied. + * + * @param StudipCache $cache The cache object to apply the operations to + */ + public static function apply(StudipCache $cache) + { + self::findEachBySQL(function ($item) use ($cache) { + $parameters = unserialize($item->parameters); + array_unshift($parameters, $item->cache_key); + call_user_func_array([$cache, $item->operation], $parameters); + + $item->delete(); + }, '1 ORDER BY chdate ASC'); + } +} |
