summaryrefslogtreecommitdiff
path: root/public/app/extends/Cache_service.php
blob: 05fd39e6f11ab35fb7d98b1d37ad9dff848224a6 (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
<?php 
namespace app\extends;

use app\models\Cms_model;
use app\models\Access_model;

/** Cache service
 * -----------------------------------------------------------------------------
 * 
 * class that gathers common source-expensive queries
 * and helps for performance optimization
 * 
 * when forcing cache creation the following option is used:
 * $options = PROXY_IGNORE_CACHE
 * 
 */
class Cache_service
{

    public static function courses_struct( $options = 0 )
    {
        return proxy(                  // cache-get courses
            [\app\models\Cms_model::class, 'courses_struct'],
            [], CACHE_ROOT_TTL,
            $options
        );
    }

    public static function files_attributes( $options = 0 )
    {
        return  proxy(
            [\app\models\Cms_model::class, 'files'],
            [], CACHE_ROOT_TTL,
            $options
        );
    }


    /** entity
     * 
     * create and retrieve a cached array of some entity
     * 
     * @param $entiry (string|method): method of the main CMS model
     * NOTE: CRITICAL: method must exist in the main CMS model
     */
    public static function entity( $entity, $options = 0 )
    {
        $allowed_methods = [    // to make sure method existence
            'page',
            'course',
            'lesson',
        ];

        // TODO: needs testing before release
        // return proxy(
        //     [\app\models\Cms_model::class, $entity],
        //     [], CACHE_ROOT_TTL,
        //     $options
        // );
    }


}