Skip to content

Commit 776f816

Browse files
committed
Version 2.0.0 Commit
1 parent 4dbb4f2 commit 776f816

7 files changed

Lines changed: 185 additions & 565 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/vendor/
2+
/tmp/
3+
/cache/
4+
/.idea/
5+
/.vscode/
6+
composer.lock

CHANGELOG.md

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
# Changelog
22

3-
**1.2.1** :: *February 13, 2016*
4-
5-
- Fixed uncompress bug.
6-
7-
**1.2.0** :: *July 13, 2015*
8-
9-
- Implemented cache config file to save the cache file configurations.
10-
- Added new methods `delete`, `flush_expired` and `flush`.
11-
- Fixed uncompress bug.
12-
13-
**1.1.0** :: *July 12, 2015*
14-
15-
- Implemented JSON decoder to convert JSON files to array.
16-
- Added support for caching objects & arrays.
17-
- Fixed compress bugs.
18-
19-
**1.0.0** :: *July 6, 2015*
20-
21-
- First public version.
3+
## v2.0.0 – 2025-10-07
4+
### Added
5+
- File locking for thread-safe writes
6+
- Per-key TTL support
7+
- Automatic expired cache cleanup
8+
- Input sanitization for keys
9+
- Optional compression and logging
10+
- PHPUnit test suite
11+
- Composer autoload support
12+
13+
### Improved
14+
- Modular structure for easier extension (e.g., Redis backend)
15+
- Better error handling
16+
- More robust README with usage examples

LICENSE.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
MIT License
22

3-
Copyright (c) 2017 Hemn Chawroka
4-
3+
Copyright (c) 2025
54
Permission is hereby granted, free of charge, to any person obtaining a copy
65
of this software and associated documentation files (the "Software"), to deal
76
in the Software without restriction, including without limitation the rights
87
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
98
copies of the Software, and to permit persons to whom the Software is
109
furnished to do so, subject to the following conditions:
1110

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
1413

1514
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1615
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

README.md

Lines changed: 35 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,55 @@
1-
# PHP EasyCache
1+
# PHP EasyCache 🚀
22

3-
The PHP EasyCache Class is an easy & fast way to cache 3rd party API calls with lossless data compression support.
3+
A lightweight, secure, and extendable caching library for PHP — now safer, faster, and more flexible.
44

5-
## Install
5+
---
66

7-
Install via [composer](https://getcomposer.org):
7+
## Features
8+
✅ File locking for thread-safe writes
9+
✅ Automatic expired cache cleanup
10+
✅ Per-key TTL
11+
✅ Key sanitization (security)
12+
✅ Optional compression
13+
✅ PHPUnit test support
814

9-
```javascript
10-
{
11-
"require": {
12-
"iprodev/php-easycache": "~1.2"
13-
}
14-
}
15-
```
16-
17-
Run `composer install` then use as normal:
15+
---
1816

19-
```php
20-
require 'vendor/autoload.php';
21-
$cache = new iProDev\Util\EasyCache();
17+
## Installation
18+
```bash
19+
composer require iprodev/php-easycache
2220
```
2321

24-
## Usage
25-
26-
A very basic usage example:
22+
---
2723

24+
## Usage
2825
```php
29-
$cache = new iProDev\Util\EasyCache();
30-
$latest_tweet = $cache->get_data('tweet', 'http://search.twitter.com/search.atom?q=from:chawroka&rpp=1');
31-
var_dump($latest_tweet);
32-
```
33-
34-
A more advanced example:
26+
use Iprodev\EasyCache\EasyCache;
3527

36-
```php
37-
$cache = new iProDev\Util\EasyCache();
38-
$cache->cache_path = 'cache/';
39-
$cache->cache_time = 3600;
28+
$cache = new EasyCache([
29+
'cache_path' => __DIR__ . '/tmp/',
30+
'cache_time' => 600,
31+
'compression_level' => 3
32+
]);
4033

41-
$data = $cache->get('identity_keyword');
34+
$data = $cache->get('github_data');
4235

43-
if(!$data) {
44-
$data = $cache->get_contents('http://some.api.com/file.json');
45-
$cache->set('identity_keyword', $data);
36+
if (!$data) {
37+
$data = file_get_contents('https://api.github.com/repos/iprodev/PHP-EasyCache');
38+
$cache->set('github_data', $data, 300);
4639
}
4740

48-
var_dump($data);
41+
echo $data;
4942
```
5043

51-
An example with compressing data:
52-
53-
```php
54-
$cache = new iProDev\Util\EasyCache();
55-
$cache->compress_level = 9;
56-
57-
$data = $cache->get_data('identity_keyword', 'http://some.api.com/file.json');
58-
59-
var_dump($data);
60-
```
61-
62-
## API Methods
63-
64-
```php
65-
$data = "Some data to cache";
66-
67-
// Call EasyCache
68-
$cache = new iProDev\Util\EasyCache();
69-
70-
// SET a Data into Cache
71-
$cache->set('identity_keyword', $data);
72-
73-
// GET a Data from Cache
74-
$data = $cache->get('identity_keyword');
75-
76-
// Check that the data is cached
77-
$is_cached = $cache->is_cached('identity_keyword');
78-
79-
// Get the Data from URL and cache it
80-
$data = $cache->get_data('identity_keyword', 'http://search.twitter.com/search.atom?q=from:chawroka&rpp=1');
81-
82-
// Helper function for retrieving data from url without cache
83-
$data = $cache->get_contents('http://search.twitter.com/search.atom?q=from:chawroka&rpp=1');
84-
85-
// REMOVE a Cache item
86-
$cache->delete('identity_keyword');
87-
88-
// REMOVES all Cache expired items
89-
$cache->flush_expired();
90-
91-
// REMOVES all Cache items
92-
$cache->flush();
93-
```
94-
95-
96-
## Configuration
97-
98-
```php
99-
// Call EasyCache
100-
$cache = new iProDev\Util\EasyCache();
101-
102-
// Path to cache folder (with trailing /)
103-
$cache->cache_path = 'cache/';
104-
105-
// Cache file extension
106-
$cache->cache_extension = '.cache';
107-
108-
// Length of time to cache a file (in seconds)
109-
$cache->cache_time = 3600;
44+
---
11045

111-
// Lossless data compression level. 1 - 9; 0 to disable
112-
$cache->compress_level = 0;
46+
## Running Tests
47+
```bash
48+
composer install
49+
composer test
11350
```
11451

115-
## Credits
52+
---
11653

117-
PHP EasyCache was created by [Hemn Chawroka](http://iprodev.com) from [iProDev](http://iprodev.com). Released under the MIT license.
54+
## License
55+
MIT © [iprodev](https://github.com/iprodev)

composer.json

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,18 @@
11
{
22
"name": "iprodev/php-easycache",
3+
"description": "A lightweight, secure, and extendable caching system for PHP.",
34
"type": "library",
4-
"description": "A simple & fast script for caching 3rd party API calls easily in PHP.",
5-
"keywords": [
6-
"fast cache",
7-
"easy cache",
8-
"simple cache",
9-
"fastcache",
10-
"easycache",
11-
"simplecache",
12-
"cache"
13-
],
14-
"homepage": "https://github.com/iprodev/PHP-EasyCache",
155
"license": "MIT",
16-
"authors": [
17-
{
18-
"name": "Hemn Chawroka",
19-
"email": "hemn@iprodev.com",
20-
"homepage": "http://iprodev.com"
21-
}
22-
],
23-
"require": {
24-
"php": ">=5.3.0"
25-
},
266
"autoload": {
277
"psr-4": {
28-
"iProDev\\Util\\": "src/"
8+
"Iprodev\\\\EasyCache\\\\": "src/"
299
}
10+
},
11+
"require": {},
12+
"require-dev": {
13+
"phpunit/phpunit": "^11.0"
14+
},
15+
"scripts": {
16+
"test": "phpunit --colors=always"
3017
}
31-
}
18+
}

0 commit comments

Comments
 (0)