Skip to content

Commit d5935a4

Browse files
committed
Composer integration
1 parent 3476256 commit d5935a4

File tree

4 files changed

+91
-12
lines changed

4 files changed

+91
-12
lines changed

README.md

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,57 @@ PHP Cache Class (File base)
33
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/)
44

55
## Enhanced Features
6+
67
* Data is serialized and JSON encoded
78
* Cache data is encrypted by `mcrypt`
89
* File Based Cache was explained [here](http://af-design.com/blog/2010/07/30/simple-file-based-caching-in-php/)
910

1011
## 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+
1144
```php
1245
//require the class
13-
require_once("lib/class.cache.php");
46+
require_once("lib/Cache.php");
1447

1548
//create new instance of the class
16-
$cache = new Cache("tmp/");
49+
use rothkj1022\Cache;
50+
$cache = new Cache\Cache("tmp/");
1751

1852
//...
1953
```
2054

2155
## Sample Call
56+
2257
```php
2358
$cache_key = "client_list";
2459

@@ -29,37 +64,50 @@ if (!$clients_data = $cache->get($cache_key)) {
2964

3065
//set the cache up!
3166
$expire = 3600; //1 hour
32-
$cache->set($cache_key, $clients_data, $expire);
67+
$cache->set($cache_key, $clients_data, $expire);
3368
}
3469

3570
var_dump($clients_data);
3671
```
3772

3873
## Reference
74+
3975
Code reference for you to get started!
4076

4177
### Properties
78+
4279
* `protected $root = '/tmp/';` - Value is pre-pended to the cache, should be the full path to the directory.
4380
* `protected $error = null;` - For holding any error messages that may have been raised
4481
* `private $_encryption_key = 'Fil3C@ch33ncryptionK3y'` - Main key used for encryption (you need to set this up inside the class)
4582

4683
### Methods
84+
4785
#### Public Methods
86+
4887
* `Cache::get($key)` - Reads the data from the cache specified by the cache key
4988
* `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
5089
* `Cache::delete($key)` - Deletes the cache specified by the `$key`
5190
* `Cache::get_error()` - Reads and clears the internal error
5291
* `Cache::have_error()` - Can be used to inspect internal error
5392

5493
#### Private Methods
55-
See code to see all private methods used like `Cahce::_encrypt($pure_string)` etc.
5694

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.
96+
97+
## Changelog
98+
99+
### Version 2.1.0
100+
101+
* Added: Composer integration
102+
* Added: changelog
59103

60104
## Credits
61-
© 2011-2014 - Coded by Jovanni Lo / [@lodev09](http://twitter.com/lodev09)
105+
106+
2010 - Authored by Erik Giberti
107+
2011-2014 - Rewritten by Jovanni Lo / [@lodev09](https://twitter.com/lodev09)
108+
2018 - Modified by Kevin Roth / [@rothkj1022](https://twitter.com/rothkj1022)
62109

63110
## License
111+
64112
Released under the [MIT License](http://opensource.org/licenses/MIT).
65113
See [LICENSE](LICENSE) file.

composer.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "rothkj1022/php-cache-class",
3+
"description": "A simple file based cache based from Erik Giberti's FileCache class, forked from lodev09/php-cache-class.",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Erik Giberti"
9+
},
10+
{
11+
"name": "Jovanni Lo",
12+
"email": "[email protected]",
13+
"homepage": "http://www.lodev09.com/"
14+
},
15+
{
16+
"name": "Kevin Roth",
17+
"homepage": "https://kevinroth.com/"
18+
}
19+
],
20+
"require": {
21+
"php": "^5.2 || ^7.0"
22+
},
23+
"autoload": {
24+
"psr-4": {
25+
"rothkj1022\\Cache\\": "lib"
26+
}
27+
}
28+
}

index.php renamed to example.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
22

33
//require the class
4-
require_once("lib/class.cache.php");
4+
require_once("lib/Cache.php");
55

66
//create new instance of the class
7-
$cache = new Cache("tmp/");
7+
use rothkj1022\Cache;
8+
$cache = new Cache\Cache("tmp/");
89

910
$cache_key = "client_list";
1011

@@ -15,8 +16,7 @@
1516

1617
//set the cache up!
1718
$expire = 3600; //1 hour
18-
$cache->set($cache_key, $clients_data, $expire);
19+
$cache->set($cache_key, $clients_data, $expire);
1920
}
2021

2122
var_dump($clients_data);
22-
?>

lib/class.cache.php renamed to lib/Cache.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<?php
2+
namespace rothkj1022\Cache;
23

34
/**
45
* @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/)
56
* @link http://www.lodev09.com
7+
* @author Erik Giberti
68
* @author Jovanni Lo
9+
* @author Kevin Roth
710
* @copyright 2014 Jovanni Lo, all rights reserved
811
* @license
912
* The MIT License (MIT)
@@ -250,7 +253,7 @@ private function _decrypt($encrypted_string) {
250253
$iv_size = openssl_cipher_iv_length($this->_encryption_method);
251254
$iv = mb_substr($encrypted_string, 0, $iv_size, '8bit');
252255
$ciphertext = mb_substr($encrypted_string, $iv_size, null, '8bit');
253-
256+
254257
$decrypted_string = openssl_decrypt($ciphertext, $this->_encryption_method, $this->_encryption_key, OPENSSL_RAW_DATA, $iv);
255258
}
256259
return $decrypted_string;

0 commit comments

Comments
 (0)