Select Git revision
authorize.php
Forked from
Stud.IP / Stud.IP
Source project has a limited visibility.
-
Jan-Hendrik Willms authored
Closes #4333 Merge request studip/studip!3134
Jan-Hendrik Willms authoredCloses #4333 Merge request studip/studip!3134
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
StudipCachedArray.php 5.07 KiB
<?php
/**
* This class represents an array in cache and removes the neccessity to
* encode/decode and store the data after every change.
*
* @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
* @license GPL2 or any later version
* @since Stud.IP 5.0
*/
class StudipCachedArray implements ArrayAccess
{
protected $key;
protected $cache;
protected $duration;
protected $data = [];
protected $hash;
/**
* Constructs the cached array
*
* @param string $key Cache key where the array is/should be stored
* an int which will be length of the substring
* of the given chache offset or a callable which
* will return the partition key.
* @param int $duration Duration in seconds for which the item shall be
* stored
*/
public function __construct(string $key, int $duration = \Studip\Cache\Cache::DEFAULT_EXPIRATION)
{
$this->key = self::class . "/{$key}";
$this->cache = \Studip\Cache\Factory::getCache();
$this->duration = $duration;
$this->hash = $this->getHash();
$this->reset();
}
/**
* Clears cached values from memory, but does not remove them from the cache.
*/
public function reset(): void
{
$this->data = [];
}
/**
* Removes all values from the cache.
*/
public function expire(): void
{
$this->hash = $this->getHash(true);
$this->reset();
}
/**
* Determines whether an offset exists in the array.
*
* @param string $offset Offset
*
* @return bool
*/
public function offsetExists($offset): bool
{
$this->loadData($offset);
return isset($this->data[$offset]);
}
/**