You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+55-7Lines changed: 55 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,22 +3,57 @@ PHP Cache Class (File base)
3
3
A simple file based cache based from Erik Giberti's FileCache class. See [here](http://af-design.com/blog/2010/07/30/simple-file-based-caching-in-php/)
4
4
5
5
## Enhanced Features
6
+
6
7
* Data is serialized and JSON encoded
7
8
* Cache data is encrypted by `mcrypt`
8
9
* File Based Cache was explained [here](http://af-design.com/blog/2010/07/30/simple-file-based-caching-in-php/)
9
10
10
11
## Installation
12
+
13
+
Run the following command in your command line shell in your php project
14
+
15
+
```sh
16
+
$ composer require rothkj1022/php-cache-class
17
+
```
18
+
19
+
Done.
20
+
21
+
You may also edit composer.json manually then perform ```composer update```:
22
+
23
+
```
24
+
"require": {
25
+
"rothkj1022/php-cache-class": "^2.1.0"
26
+
}
27
+
```
28
+
29
+
## Getting started
30
+
31
+
### Example usage with composer
32
+
33
+
```php
34
+
//load composer packages
35
+
require('vendor/autoload.php');
36
+
37
+
//create new instance of the class
38
+
use rothkj1022\Cache;
39
+
$cache = new Cache\Cache("tmp/");
40
+
```
41
+
42
+
### Example usage without composer
43
+
11
44
```php
12
45
//require the class
13
-
require_once("lib/class.cache.php");
46
+
require_once("lib/Cache.php");
14
47
15
48
//create new instance of the class
16
-
$cache = new Cache("tmp/");
49
+
use rothkj1022\Cache;
50
+
$cache = new Cache\Cache("tmp/");
17
51
18
52
//...
19
53
```
20
54
21
55
## Sample Call
56
+
22
57
```php
23
58
$cache_key = "client_list";
24
59
@@ -29,37 +64,50 @@ if (!$clients_data = $cache->get($cache_key)) {
29
64
30
65
//set the cache up!
31
66
$expire = 3600; //1 hour
32
-
$cache->set($cache_key, $clients_data, $expire);
67
+
$cache->set($cache_key, $clients_data, $expire);
33
68
}
34
69
35
70
var_dump($clients_data);
36
71
```
37
72
38
73
## Reference
74
+
39
75
Code reference for you to get started!
40
76
41
77
### Properties
78
+
42
79
*`protected $root = '/tmp/';` - Value is pre-pended to the cache, should be the full path to the directory.
43
80
*`protected $error = null;` - For holding any error messages that may have been raised
44
81
*`private $_encryption_key = 'Fil3C@ch33ncryptionK3y'` - Main key used for encryption (you need to set this up inside the class)
45
82
46
83
### Methods
84
+
47
85
#### Public Methods
86
+
48
87
*`Cache::get($key)` - Reads the data from the cache specified by the cache key
49
88
*`Cache::set($key [, $data, $ttl])` - Saves data to the cache. Anything that evaluates to false, null, '', boolean false, 0 will not be saved. `$ttl` Specifies the expiry time
50
89
*`Cache::delete($key)` - Deletes the cache specified by the `$key`
51
90
*`Cache::get_error()` - Reads and clears the internal error
52
91
*`Cache::have_error()` - Can be used to inspect internal error
53
92
54
93
#### Private Methods
55
-
See code to see all private methods used like `Cahce::_encrypt($pure_string)` etc.
56
94
57
-
## Feedback
58
-
All bugs, feature requests, pull requests, feedback, etc., are welcome. Visit my site at [www.lodev09.com](http://www.lodev09.com"www.lodev09.com") or email me at [[email protected]](mailto:[email protected])
95
+
See code to see all private methods used like `Cache::_encrypt($pure_string)` etc.
Copy file name to clipboardExpand all lines: lib/Cache.php
+4-1Lines changed: 4 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,12 @@
1
1
<?php
2
+
namespacerothkj1022\Cache;
2
3
3
4
/**
4
5
* @package Cache - A simple file based cache (based from Erik Giberti's FileCache class. http://af-design.com/blog/2010/07/30/simple-file-based-caching-in-php/)
5
6
* @link http://www.lodev09.com
7
+
* @author Erik Giberti
6
8
* @author Jovanni Lo
9
+
* @author Kevin Roth
7
10
* @copyright 2014 Jovanni Lo, all rights reserved
8
11
* @license
9
12
* The MIT License (MIT)
@@ -250,7 +253,7 @@ private function _decrypt($encrypted_string) {
0 commit comments