1 | <?php |
||
13 | class Cache |
||
14 | { |
||
15 | |||
16 | const JSON = 1; |
||
17 | const TEXT = 2; |
||
18 | const GZIP = 3; |
||
19 | const JSONGZ = 4; |
||
20 | |||
21 | use SingletonTrait; |
||
22 | |||
23 | /** |
||
24 | * Método que guarda un text en un fichero |
||
25 | * @param string $data |
||
26 | * @param string $path |
||
27 | * @param boolean $absolute |
||
28 | * @throws ConfigException |
||
29 | */ |
||
30 | 5 | private function saveTextToFile($data, $path, $absolute = false) |
|
39 | |||
40 | /** |
||
41 | * Método que extrae el texto de un fichero |
||
42 | * @param string $path |
||
43 | * @param int $transform |
||
44 | * @param boolean $absolute |
||
45 | * @return array|string|null |
||
46 | */ |
||
47 | 5 | public function getDataFromFile($path, $transform = Cache::TEXT, $absolute = false) |
|
56 | |||
57 | /** |
||
58 | * Método que verifica si un fichero tiene la cache expirada |
||
59 | * @param string $path |
||
60 | * @param int $expires |
||
61 | * @param boolean $absolute |
||
62 | * @return bool |
||
63 | */ |
||
64 | 1 | private function hasExpiredCache($path, $expires = 300, $absolute = false) |
|
70 | |||
71 | /** |
||
72 | * Método que transforma los datos de salida |
||
73 | * @param string $data |
||
74 | * @param int $transform |
||
75 | * @return array|string|null |
||
76 | */ |
||
77 | 5 | public static function extractDataWithFormat($data, $transform = Cache::TEXT) |
|
96 | |||
97 | /** |
||
98 | * Método que transforma los datos de entrada del fichero |
||
99 | * @param string $data |
||
100 | * @param int $transform |
||
101 | * @return string |
||
102 | */ |
||
103 | 5 | public static function transformData($data, $transform = Cache::TEXT) |
|
121 | |||
122 | /** |
||
123 | * Método que guarda en fichero los datos pasados |
||
124 | * @param $path |
||
125 | * @param $data |
||
126 | * @param int $transform |
||
127 | * @param boolean $absolutePath |
||
128 | */ |
||
129 | 5 | public function storeData($path, $data, $transform = Cache::TEXT, $absolutePath = false) |
|
134 | |||
135 | /** |
||
136 | * Método que verifica si tiene que leer o no un fichero de cache |
||
137 | * @param string $path |
||
138 | * @param int $expires |
||
139 | * @param callable $function |
||
140 | * @param int $transform |
||
141 | * @return string|null |
||
142 | */ |
||
143 | 1 | public function readFromCache($path, $expires = 300, callable $function, $transform = Cache::TEXT) |
|
156 | |||
157 | /** |
||
158 | * Método estático que revisa si se necesita cachear la respuesta de un servicio o no |
||
159 | * @return integer|boolean |
||
160 | */ |
||
161 | 1 | public static function needCache() |
|
170 | |||
171 | /** |
||
172 | * Método que construye un hash para almacenar la cache |
||
173 | * @return string |
||
174 | */ |
||
175 | 1 | public function getRequestCacheHash() |
|
184 | } |
||
185 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.