This repository was archived by the owner on Jul 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
64 lines (45 loc) · 1.38 KB
/
test.php
File metadata and controls
64 lines (45 loc) · 1.38 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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// include_once "vendor/autoload.php";
// Just included in order to test.
include_once "DBCache.php";
include_once "DB.php";
include_once "DBInstance.php";
use Cache\DBCache;
// Connect to PDO sqlite
$pdo_url = 'sqlite:./database.lite';
// Create a connection
$conn = new PDO($pdo_url);
// Create cache object - second param is the DB cache table
$cache = new DBCache($conn, 'cache_system');
// Some kind of unique key. Usually a string but an array or object will work as well
$cache_key = array('Hello world');
// Use assoc in json_decode
$cache->assoc = true;
// Cache for 10 seconds
$cache_res = $cache->get($cache_key, 10);
// Cache return NULL if no result or if result is outdated
if ($cache_res === null) {
echo "No cache result. Setting cache\n";
$cache_value = array(0 => 'test', 'str_key' => 'Hello there World ÆØÅ! and som random stuff: ' . rand());
echo "Setting cache\n";
$cache->set($cache_key, $cache_value);
} else {
// output the cache result
print_r($cache_res);
}
// Test for a bit more variables
function test_10000($cache)
{
for ($i = 0; $i < 10000; $i++) {
if ($i % 1000 === 0) {
echo "$i\n";
}
$cache->set($i, $i . ' ' . rand());
}
}
// test_10000($cache);
$res = $cache->get(7985);
var_dump($res);