blob: 8fe7d35624ddb0d0d47079ed51cce3b08e69a2f7 (
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
<?php
/**
* Elgg cache
* Cache file interface for caching data.
*
* @package Elgg.Core
* @subpackage Cache
*/
/**
* Returns an ElggCache object suitable for caching view
* file load paths to disk under $CONFIG->dataroot.
*
* @todo Can this be done in a cleaner way?
* @todo Swap to memcache etc?
*
* @return ElggFileCache A cache object suitable for caching file load paths.
*/
function elgg_get_filepath_cache() {
global $CONFIG;
/**
* A default filestore cache using the dataroot.
*/
static $FILE_PATH_CACHE;
if (!$FILE_PATH_CACHE) {
$FILE_PATH_CACHE = new ElggFileCache($CONFIG->dataroot);
}
return $FILE_PATH_CACHE;
}
/**
* Deletes the view file paths cache from disk.
*
* @return bool On success
*/
function elgg_filepath_cache_reset() {
$cache = elgg_get_filepath_cache();
return $cache->delete('view_paths');
}
/**
* Saves $data to the views file paths disk cache as
* 'view_paths'.
*
* @param mixed $data The data
*
* @return bool On success
*/
function elgg_filepath_cache_save($data) {
global $CONFIG;
if ($CONFIG->viewpath_cache_enabled) {
$cache = elgg_get_filepath_cache();
return $cache->save('view_paths', $data);
}
return false;
}
/**
* Returns the contents of the views file paths cache from disk.
*
* @return mixed Null if simplecache isn't enabled, the contents of the
* views file paths cache if it is.
*/
function elgg_filepath_cache_load() {
global $CONFIG;
if ($CONFIG->viewpath_cache_enabled) {
$cache = elgg_get_filepath_cache();
$cached_view_paths = $cache->load('view_paths');
if ($cached_view_paths) {
return $cached_view_paths;
}
}
return NULL;
}
/**
* Enables the views file paths disk cache.
*
* Uses the 'viewpath_cache_enabled' datalist with a boolean value.
* Resets the views paths cache.
*
* @return null
*/
function elgg_enable_filepath_cache() {
global $CONFIG;
datalist_set('viewpath_cache_enabled', 1);
$CONFIG->viewpath_cache_enabled = 1;
elgg_filepath_cache_reset();
}
/**
* Disables the views file paths disk cache.
*
* Uses the 'viewpath_cache_enabled' datalist with a boolean value.
* Resets the views paths cache.
*
* @return null
*/
function elgg_disable_filepath_cache() {
global $CONFIG;
datalist_set('viewpath_cache_enabled', 0);
$CONFIG->viewpath_cache_enabled = 0;
elgg_filepath_cache_reset();
}
|