forked from lodev09/php-cache-class
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.php
More file actions
28 lines (22 loc) · 796 Bytes
/
example.php
File metadata and controls
28 lines (22 loc) · 796 Bytes
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
<?php
//load composer packages
require('vendor/autoload.php');
//require the class
require_once("lib/FileCache.php");
//create new instance of the class
use rothkj1022\FileCache;
$cache = new FileCache\FileCache("tmp/");
$cache_key = "client_list";
//see if we can get an existing cache
if (!$clients_data = $cache->get($cache_key)) {
//nope. Let's get the real one then!
$clients_data = json_decode(file_get_contents("clients.json"));
//set the cache up!
$expire = 3600; //1 hour
$cache->set($cache_key, $clients_data, $expire);
}
var_dump($clients_data);
//get external url, and cache the contents
$uri = 'https://raw.githubusercontent.com/bahamas10/css-color-names/master/css-color-names.json';
$remote_data = $cache->file_get_contents($uri);
var_dump($remote_data);