-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.php
68 lines (47 loc) · 1.07 KB
/
example.php
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
use jtk\simple_php_cache\FileCache;
use jtk\simple_php_cache\ArrayCache;
require __DIR__ . '/vendor/autoload.php';
session_start();
function example($cache)
{
var_dump(strval(get_class($cache)));
$identifier = "my_example_has_get_set";
if($cache->has($identifier))
{
var_dump($cache->get($identifier));
}
else
{
var_dump($cache->set($identifier, "my value"));
}
$function = $cache->wrap(function($x, $y)
{
return $x + $y;
});
for($i = 0; $i < 10000; ++$i)
{
var_dump($function(rand(0, 9), rand(0, 9)));
}
}
$start = microtime(true);
if(!file_exists('./cache/'))
{
mkdir('./cache/');
}
$filecache = new FileCache(__DIR__.'/cache/', 50);
//$cache->clear();
example($filecache);
echo 'time:' . (microtime(true) - $start);
$start = microtime(true);
if(!isset($_SESSION['cache']))
{
$_SESSION['cache'] = [];
}
$sessioncache = new ArrayCache(
$_SESSION['cache']);
//$cache->clear();
example($sessioncache);
echo 'time:' . (microtime(true) - $start);
$filecache->set('session', $_SESSION);
var_dump($filecache->get('session'));