aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/cas/CAS_PGTStorage_Cache.php
blob: 61ce9fa6ad0f7066c868eb936bf115509698acfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
 * CAS_PGTStorage_Cache.php - PGTStorage backend using StudipCache
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * @author      Elmar Ludwig
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category    Stud.IP
 */
class CAS_PGTStorage_Cache extends CAS_PGTStorage_AbstractStorage
{
    /**
     * This method returns an informational string giving the type of storage
     * used by the object (used for debugging purposes).
     *
     * @return an informational string.
     */
    public function getStorageType()
    {
        return 'cache';
    }

    /**
     * This method returns an informational string giving informations on the
     * parameters of the storage (used for debugging purposes).
     *
     * @return an informational string.
     */
    public function getStorageInfo()
    {
        return 'type=' . Config::get()->SYSTEMCACHE['type'];
    }

    /**
     * This method stores a PGT and its corresponding PGT Iou in the cache.
     *
     * @param string $pgt     the PGT
     * @param string $pgt_iou the PGT iou
     */
    public function write($pgt, $pgt_iou)
    {
        $cache = \Studip\Cache\Factory::getCache();
        $cache_key = 'pgtiou/' . $pgt_iou;
        return $cache->write($cache_key, $pgt);
    }

    /**
     * This method reads a PGT corresponding to a PGT Iou and deletes the
     * corresponding cache entry.
     *
     * @param string $pgt_iou the PGT iou
     *
     * @return the corresponding PGT, or FALSE on error
     */
    public function read($pgt_iou)
    {
        $cache = \Studip\Cache\Factory::getCache();
        $cache_key = 'pgtiou/' . $pgt_iou;
        $pgt = $cache->read($cache_key);
        $cache->expire($cache_key);
        return $pgt;
    }
}