-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathwpGithubCache.php
More file actions
68 lines (59 loc) · 1.33 KB
/
Copy pathwpGithubCache.php
File metadata and controls
68 lines (59 loc) · 1.33 KB
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
<?php
/**
* WpGithubCache
* Author: Pablo Cornehl
* Author URI: http://www.seinoxygen.com
* Github : https://github.com/seinoxygen/wp-github
* Version: 1.0
*/
class WpGithubCache {
private $path = NULL;
public $timeout = 600;
/**
* WpGithubCache constructor.
*/
public function __construct() {
$this->path = dirname(__FILE__) . "/../cache/";
}
/**
* Get cache file.
* @param $file
* @return array|mixed|null|object
*/
public function get($file) {
$file = $this->path . $file;
if(file_exists($file)){
$file_age = filemtime($file) + $this->timeout;
$file_timed_out = intval($file_age - time());
$content = json_decode(file_get_contents($file));
if ( $file_timed_out > 0 && is_array($content)) {
return $content;
} else {
return null;
}
} else {
return null;
}
}
/**
* Set cache file.
* create static file
* @param $file
* @param $content
*/
public function set($file, $content) {
@file_put_contents($this->path . $file, json_encode($content));
}
/**
* clear
* delete all files
*/
public function clear() {
$files = glob($this->path . '*.json');
foreach ($files as $file) {
if (is_file($file)) {
@unlink($file);
}
}
}
}