Skip to content

Commit ad8b8dd

Browse files
authored
Merge branch 'v5' into final (#299)
* Starting V5 * Updated roadmap with important info * Multiples improvements - Re-implement [in|de]crement methods in ExtendedCacheItemInterface - Added specific Exception if the driverCheck() has failed * - Updated examples - Updated readme - Re-added legacy autoload * Fixed missing return in autoload * Added exemple for driver ssdb with standalone lib * Cleaned up some code + indexed wrapper with constants * - Re-implement touch method in ExtendedCacheItemInterface: deprecated in profit CacheItemInterface::expiresAfter() - Added missing file headers - Updated interfaces extending * Rewrite stats method to be implemented in a driverStatistic() object, not a breaking change due to ArrayAccess use, but array use is deprecated * Added beautiful psr6 badge * Validated item on checklist * Improved driver name detection for throwed exceptions * Added item to the roadmap * Implemented Devnull driver (aka void) * Fixed namespace issue with Devnull driver * Fixed Redis settings * Added Couchbase driver * Removed useless flags on Couchbase driver * - Fixed increment/decrement params in interface - Added append/preprend method to the API * Fixed interace name issue * Checked apend/prepend roadmap checklist * Wrote couchbase example * Attempting to repair tests * Removed bin dir from gitignore * Set exec flag to bin file * Excluded composer dir of syntax checker * Definately fixed travis build, i guess so... * Added custom php.ini for tests * Replaced deprecated char in custom ini * Updated v5 roadmap * Added Exception to expireAt() if type is not DateTimeInterface * Added rawData methods to driverStatistic * Remove automatically expired item in case it fails on driver itself * Added Mongodb driver * Updated README.md * Added Devfalse and Devtrue driver * Updated README.md and added driver description * Updated README.md * Updated README.md * Updated README.md * Added cache extends example * Added Apcu driver * Full code cleaning * Grouped driver names in readme * Prepared ground for tags reimplementation * Added compression support for Memcache driver - Added config field: compress_data - If compress_data is set, enabled compression in Memcache driver * Improved getTtl() method + updated Memcached flag visibility * -Re-implemented tags features (as a replacement of global search) * -Re-implemented tags features (as a replacement of global search) * Fix auto driver * Never expire when time is set to 0 * Updated phpDoc interface * Ohh common, there's not enough drivers :3 - Added Leveldb driver * Added stub files for Leveldb driver (more IDE friendly) * Fixed bad behaviour with Leveldb\driver::driverClear() * Added Scrutinizer badge * Fixed typo * Added scrutinizer conf * Removed external coverage * Updated Roadmap + Cleaned up DriverAbstract of no-longer-used methods * Repaired travis build * Code clean up + Travis build restart * Removed another unused method * Removed unused argument * Adjusted codeclimate settings. They point out by-design features of phpFastCacche. * Fixed broken build * Added advanced tags features: - incrementItemsByTag($tagName, $step = 1) // Increment items by a tag - incrementItemsByTags(array $tagNames, $step = 1) // Increment items by some tags - decrementItemsByTag($tagName, $step = 1) // Decrement items by a tag - decrementItemsByTags(array $tagNames, $step = 1) // Decrement items by some tags - appendItemsByTag($tagName, $data) // Append items by a tag - appendItemsByTags(array $tagNames, $data) // Append items by some tags - prependItemsByTag($tagName, $data) // Prepend items by a tag - prependItemsByTags(array $tagNames, $data) // Prepend items by some tags * Repaired the build, for real this time. * Splitted up methods into traits to make the abstractDriver more "abstract" * Updated trait conception * $tmp property must be owned by PathSeekerTrait * $tmp property must be owned by PathSeekerTrait * Fixed phpDoc comment * Fixed short var + updated codeclimate settings * Fixed short var + updated codeclimate settings * Removed unused var * Excluded dir in codeclimate * Added bundle-based methods * Fixed cache issue with windows * Added dependency status badge * Fixed Leveldb destructor error * Protected some properties * Added getConfig() method * Updated psr6 badge * Fixed potential issue with Files Stats * Fixed phpDoc comments * Fixed Files stats * Fixed directory write issues * Fixed phpDoc comments * Fixed Symfony profiler crashing * Improved raw data for driver Files * Updated driverStatistic entity * Fixed SF exception * Interfaced getDriverName() * Fixed wrong itemInstance behaviour * Temporary removed linear magic methods * Improved driver statistics + FilePath issues fixes * Fixed wrong var type * Merged statements * Updated drivers statistics + added xcache stub * Fixed #286 * Fixed isHit() behaviour * Protected driver-based methods * Re-enabled CacheManager warning * Not all driver clearing returns a boolean * Fixed Leveldb DriverClear notice * Mongodb sometimes does not return the Collstat size * Fixed Ssdb cache clear * Updated Wincache Info driver * Improved travis tests efficiency * Let's try the nightly ! * Improved Sqlite driver check * Ps2 compliance + added php ext-intl suggestion * Removed duplicate in readme * Update README.md * Updated roadmap * Added phpFastCacheAbstractProxy * Short array syntax * Updated extends example with Proxy class * Updated phpDoc comments * e3868ac#commitcomment-17673718 * Added getDataAsJsonString() method to the Item API * Added basic API class * Added extended JSON methods to ItemPool API * Updated examples headers to includes MIT licence * Completed readme.md with missing API methods * Removed useless information on api in readme.md * Fixed Json formatting + tags behaviour * Updating trait insertion * Re-added clean() method and deprecated it in favor of cleanr(). * Fixed return in deprecated alias * Deprecated CacheManager::setup() in favor of CacheManager::setDefaultConfig() * Re-implemented driver fallback * Re-ordered option in cache manager * Updated Readme * Specify the 7.1 for Travis * Specify the 7.1 for Travis (reverted from commit 8ae52bc) * Fixed typo * Fixed typo * Fixed #294 * Fixed #294 * Require the JSON extension as per new JSON methods * Var type adjustements
1 parent 284938c commit ad8b8dd

File tree

405 files changed

+8219
-26706
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

405 files changed

+8219
-26706
lines changed

.codeclimate.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ engines:
3838
enabled: false
3939
Controversial/CamelCaseVariableName:
4040
enabled: false
41+
Design/TooManyPublicMethods:
42+
enabled: false
43+
Design/NpathComplexity:
44+
enabled: false
4145
ratings:
4246
paths:
4347
- "**.inc"
@@ -48,4 +52,6 @@ ratings:
4852
- "**.py"
4953
- "**.rb"
5054
exclude_paths:
51-
- "src/phpFastCache/_extensions/**"
55+
- "bin/**"
56+
- "examples/**"
57+
- "tests/**"

.gitignore

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*.pydevproject
66
.project
77
.metadata
8-
bin/
98
tmp/
109
*.tmp
1110
*.bak
@@ -51,7 +50,6 @@ local.properties
5150
[Rr]elease/
5251
x64/
5352
build/
54-
[Bb]in/
5553
[Oo]bj/
5654

5755
# MSTest test Results
@@ -201,7 +199,7 @@ dist/
201199
build/
202200
eggs/
203201
parts/
204-
var/
202+
# var/
205203
sdist/
206204
develop-eggs/
207205
.installed.cfg
@@ -234,4 +232,5 @@ nbproject/
234232

235233
#Composer
236234
vendor/
237-
composer.lock
235+
composer.lock
236+
composer.phar

.scrutinizer.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
before_commands:
2+
- "composer install --no-dev --prefer-source"
3+
4+
filter:
5+
excluded_paths: ["bin/*", "docs/*", "examples/*", "var/*", "vendor/*"]
6+
checks:
7+
php: true
8+
coding_style:
9+
php:
10+
spaces:
11+
around_operators:
12+
concatenation: true
13+
tools:
14+
external_code_coverage: false
15+
php_code_coverage: true
16+
php_code_sniffer:
17+
enabled: true
18+
config:
19+
standard: PSR2
20+
filter:
21+
paths: ["src/*"]
22+
php_mess_detector:
23+
enabled: true
24+
filter:
25+
paths: ["src/*"]

.travis.yml

+8-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@
1212
language: php
1313
services:
1414
- memcached
15+
# - redis-server
16+
before_script: phpenv config-add var/php/conf/phpfastcache.ini
1517
php:
16-
- 5.3
17-
- 5.4
18+
# - 5.3
19+
# - 5.4
1820
- 5.5
1921
- 5.6
2022
- 7.0
21-
# - nightly
23+
- nightly
2224
# - hhvm We may need to do review this check later
23-
25+
install:
26+
- ./bin/ci/install_dependencies.sh
2427
script:
2528
- php -f tests/SyntaxChecker.test.php
2629
- php -f tests/Autoload.test.php
2730
- php -f tests/NewCacheInstance.test.php
31+
- php -f tests/Psr6InterfaceImplements.test.php

README.md

+100-64
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
1-
[![Code Climate](https://codeclimate.com/github/PHPSocialNetwork/phpfastcache/badges/gpa.svg)](https://codeclimate.com/github/PHPSocialNetwork/phpfastcache) [![Build Status](https://travis-ci.org/PHPSocialNetwork/phpfastcache.svg?branch=final)](https://travis-ci.org/PHPSocialNetwork/phpfastcache) [![Latest Stable Version](http://img.shields.io/packagist/v/phpfastcache/phpfastcache.svg)](https://packagist.org/packages/phpfastcache/phpfastcache) [![Total Downloads](http://img.shields.io/packagist/dt/phpfastcache/phpfastcache.svg)](https://packagist.org/packages/phpfastcache/phpfastcache) [![License](https://img.shields.io/packagist/l/phpfastcache/phpfastcache.svg)](https://packagist.org/packages/phpfastcache/phpfastcache)
1+
[![Code Climate](https://codeclimate.com/github/PHPSocialNetwork/phpfastcache/badges/gpa.svg)](https://codeclimate.com/github/PHPSocialNetwork/phpfastcache) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/PHPSocialNetwork/phpfastcache/badges/quality-score.png?b=final)](https://scrutinizer-ci.com/g/PHPSocialNetwork/phpfastcache/?branch=final) [![Build Status](https://travis-ci.org/PHPSocialNetwork/phpfastcache.svg?branch=final)](https://travis-ci.org/PHPSocialNetwork/phpfastcache) [![Latest Stable Version](http://img.shields.io/packagist/v/phpfastcache/phpfastcache.svg)](https://packagist.org/packages/phpfastcache/phpfastcache) [![Total Downloads](http://img.shields.io/packagist/dt/phpfastcache/phpfastcache.svg)](https://packagist.org/packages/phpfastcache/phpfastcache) [![Dependency Status](https://www.versioneye.com/php/phpfastcache:phpfastcache/badge.svg)](https://www.versioneye.com/php/phpfastcache:phpfastcache) [![License](https://img.shields.io/packagist/l/phpfastcache/phpfastcache.svg)](https://packagist.org/packages/phpfastcache/phpfastcache) [![Coding Standards](https://img.shields.io/badge/CI-PSR6-orange.svg)](https://github.com/php-fig/cache)
22
---------------------------
33
Simple Yet Powerful PHP Caching Class
44
---------------------------
55
More information at http://www.phpfastcache.com
66
One Class uses for All Cache. You don't need to rewrite your code many times again.
77

8-
Supported: SSDB, Redis, Predis, Cookie, Files, MemCache, MemCached, APC, WinCache, X-Cache, PDO with SQLite
8+
9+
### Supported drivers at this day *
10+
11+
| Regular drivers | High performances drivers | Development driver |
12+
|------------------|---------------------------|--------------------|
13+
| `Apc(u)` | `CouchBase` | `Devnull` |
14+
| `Cookie` | `Mongodb` | `Devfalse` |
15+
| `Files` | `Predis` | `Devtrue` |
16+
| `Leveldb` | `Redis` | |
17+
| `Memcache(d)` | `Ssdb` | |
18+
| `Sqlite` | | |
19+
| `Wincache` | | |
20+
| `Xcache` | | |
21+
22+
\* Driver descriptions available in DOCS/DRIVERS.md
23+
24+
### Symfony developers are not forgotten !
25+
Starting of the v5, phpFastCache comes with a [Symfony Bundle](https://github.com/PHPSocialNetwork/phpfastcache-bundle).
26+
He's fresh, so feel free to report any bug or contribute to the code using pull requests.
927

1028
---------------------------
1129
Not a "Traditional" Caching
1230
---------------------------
13-
phpFastCache is not a traditional caching method which is keep read and write to files, sqlite or mass connections to memcache, redis, mongodb... phpFastCache use my unique caching method.
14-
When you use Files, and Sqlite, I am guarantee you still can get fast speed almost like memcache & redis for sure. Also, when you use Memcache / Memcached, your miss hits will be reduce.
15-
Different with normal caching methods which shared everywhere on internet, phpFastCache Lib reduce the high I/O load, and faster than traditional caching method at least x7 - 10 times.
31+
phpFastCache is not a traditional caching method which is keep read and write to files, sqlite or mass connections to memcache, redis, mongodb... Also, when you use Memcache / Memcached, your miss hits will be reduce.
32+
Different with normal caching methods which shared everywhere on internet, phpFastCache Lib reduce the high I/O load, and faster than traditional caching method at least x7 ~+ times.
1633
However, some time you still want to use traditional caching, we support them too.
1734

1835
```php
1936
use phpFastCache\CacheManager;
2037

21-
// Default value: is "phpfastcache" (fastest), you can change to "normal" or "memory" (fast)
22-
CacheManager::CachingMethod("normal");
23-
24-
// Recommend: use phpfastcache to reduce files I/O & CPU Load, Memcached missing hits, and make redis and other connections become faster.
25-
// If you get any error due to Server / Hosting, try to change to "memory" , act almost same way as "phpfastcache" but slower a little bit
26-
// In bad situation, use "normal" as traditional caching method
38+
CacheManager::getInstance('files', $config);
39+
// An alternative exists:
40+
CacheManager::Files($config);
2741

2842
```
2943

@@ -38,18 +52,56 @@ With phpFastCache, your page only send 1 query to DB, and use the cache to serve
3852
Rich Development API
3953
---------------------------
4054

41-
phpFastCache offers you a lot of usefull APIS:
42-
43-
- get($keyword) // The getter, obviously, return your cache object
44-
- set($keyword, $something_your_want_to_cache, $time_as_second = 0) // The setter, for those who missed it, put 0 meant cache it forever
45-
- delete($keyword) // For removing a cached thing
46-
- clean() // Allow you to completely empty the cache and restart from the beginning
47-
- touch($keyword, $time_you_want_to_extend) // Allow you to extends the lifetime of an entry without altering the value
48-
- increment($keyword, $step = 1) // For integer that we can count on
49-
- decrement($keyword, $step = 1) // Redundant joke...
50-
- search($string_or_regex, $search_in_value = false | true) // Allow you to perform some search on the cache index
51-
- isExisting($keyword) // Check if your cache entry exists, it is the equivalent of isset()
52-
- stats() // Return the cache statistics, useful for checking disk space used by the cache etc.
55+
phpFastCache offers you a lot of useful APIs:
56+
57+
### Item API
58+
- getKey() // Return the item identifier (key)
59+
- get() // The getter, obviously, return your cache object
60+
- set($value) // The setter, for those who missed it, put 0 meant cache it forever
61+
- expiresAfter($ttl) // Allow you to extends the lifetime of an entry without altering the value (formerly known as touch())
62+
- expiresAt($expiration) // Sets the expiration time for this cache item (as a DateTimeInterface object)
63+
- increment($step = 1) // For integer that we can count on
64+
- decrement($step = 1) // Redundant joke...
65+
- append($data) // Append data to a string or an array (push)
66+
- prepend($data) // Prepend data to a string or an array (unshift)
67+
- isHit() // Check if your cache entry exists and is still valid, it is the equivalent of isset()
68+
- isExpired() // Check if your cache entry is expired
69+
- getTtl() // Get the remaining Time To Live as an integer
70+
- getExpirationDate() // Get the expiration date as a Datetime object
71+
- addTag($tagName) // Add a tag
72+
- addTags(array $tagNames) // Add many tags
73+
- setTags(array $tags) // Set some tags
74+
- getTags() // Get the tags
75+
- getTagsAsString($separator = ', ') // Get the data a string separated by $separator
76+
- removeTag($tagName) // Remove a tag
77+
- removeTags(array $tagNames) // Remove some tags
78+
- getDataAsJsonString()// Return the data as a well-formatted json string
79+
80+
### ItemPool API
81+
- getItem($key) // Retrieve an item and returns an empty item if not found
82+
- getItems(array $keys) // Retrieve one or more item and returns an array of items
83+
- getItemsAsJsonString(array $keys) // Returns A json string that represents an array of items
84+
- hasItem($key) // Tests if an item exists
85+
- deleteItem($key) // Delete an item
86+
- deleteItems(array $keys) // Delete one or more items
87+
- save(CacheItemInterface $item) // Persists a cache item immediately
88+
- saveDeferred(CacheItemInterface $item); // Sets a cache item to be persisted later
89+
- commit(); // Persists any deferred cache items
90+
- clear() // Allow you to completely empty the cache and restart from the beginning
91+
- stats() // Return the cache statistics as an object, useful for checking disk space used by the cache etc.
92+
- getItemsByTag($tagName) // Return items by a tag
93+
- getItemsByTags(array $tagNames) // Return items by some tags
94+
- getItemsByTagsAsJsonString(array $tagNames) // Returns A json string that represents an array of items by tags-based
95+
- deleteItemsByTag($tagName) // Delete items by a tag
96+
- deleteItemsByTags(array $tagNames) // Delete items by some tags
97+
- incrementItemsByTag($tagName, $step = 1) // Increment items by a tag
98+
- incrementItemsByTags(array $tagNames, $step = 1) // Increment items by some tags
99+
- decrementItemsByTag($tagName, $step = 1) // Decrement items by a tag
100+
- decrementItemsByTags(array $tagNames, $step = 1) // Decrement items by some tags
101+
- appendItemsByTag($tagName, $data) // Append items by a tag
102+
- appendItemsByTags(array $tagNames, $data) // Append items by some tags
103+
- prependItemsByTag($tagName, $data) // Prepend items by a tag
104+
- prependItemsByTags(array $tagNames, $data) // Prepend items by some tags
53105

54106
Also support Multiple calls, Tagging, Setup Folder for caching. Look at our examples folders.
55107

@@ -69,68 +121,52 @@ composer require phpFastCache/phpFastCache
69121
```php
70122
use phpFastCache\CacheManager;
71123

72-
// require_once ('vendor/autoload.php');
124+
// Setup File Path on your config files
125+
CacheManager::setup(array(
126+
"path" => '/var/www/phpfastcache.com/dev/tmp', // or in windows "C:/tmp/"
127+
));
73128

74-
$cache = CacheManager::Files();
75-
76-
// $cache = CacheManager::Memcached();
77-
// phpFastCache supported: SSDB, Redis, Predis, Cookie, Files, MemCache, MemCached, APC, WinCache, XCache, SQLite
78-
// $cache = CacheManager::getInstance("auto", $config);
79-
// $cache = CacheManager::getInstance("memcached", $server_config);
129+
// In your class, function, you can call the Cache
130+
$InstanceCache = CacheManager::getInstance('files');
80131

81132
/**
82133
* Try to get $products from Caching First
83134
* product_page is "identity keyword";
84135
*/
85136
$key = "product_page";
86-
$products = $cache->get($key);
137+
$CachedString = $InstanceCache->getItem($key);
138+
139+
$your_product_data = [
140+
'First product',
141+
'Second product',
142+
'Third product'
143+
// etc...
144+
];
87145

88-
if (is_null($products)) {
89-
$products = "DB QUERIES | FUNCTION_GET_PRODUCTS | ARRAY | STRING | OBJECTS";
90-
// Write products to Cache in 10 minutes with same keyword
91-
$cache->set($key, $products, 600);
146+
if (is_null($CachedString->get())) {
147+
$CachedString->set($your_product_data)->expiresAfter(5);//in seconds, also accepts Datetime
148+
$InstanceCache->save($CachedString); // Save the cache item just like you do with doctrine and entities
92149

93-
echo " --> NO CACHE ---> DB | Func | API RUN FIRST TIME ---> ";
150+
echo "FIRST LOAD // WROTE OBJECT TO CACHE // RELOAD THE PAGE AND SEE // ";
151+
echo $CachedString->get();
94152

95153
} else {
96-
echo " --> USE CACHE --> SERV 10,000+ Visitors FROM CACHE ---> ";
154+
echo "READ FROM CACHE // ";
155+
echo $CachedString->get()[0];// Will prints 'First product'
97156
}
98157

99158
/**
100159
* use your products here or return it;
101160
*/
102-
echo $products;
103-
104-
```
105-
106-
#### :floppy_disk: Legacy / Lazy Method (Without Composer)
107-
```php
108-
// In your config files
109-
// require_once ('phpFastCache/src/autoload.php');
110-
111-
use phpFastCache\CacheManager;
112-
113-
// $cache = $cache = CacheManager::Files();
114-
// $cache = phpFastCache();
115-
// $cache = phpFastCache("files");
116-
// $cache = phpFastCache("memcached");
117-
118-
/**
119-
* Try to get $products from Caching First
120-
* product_page is "identity keyword";
121-
*/
122-
$key = "product_page";
123-
// $products = $cache->get($key);
124-
$products = CacheManager::get($key);
125-
// CacheManager::set() , ::touch ::increment ::search ..etc, work same way without create new instance
126-
127-
// yet it's the same as autoload
161+
echo implode('<br />', $CachedString->get());// Will echo your product list
128162

129163
```
130164

165+
##### :floppy_disk: Legacy / Lazy Method (Without Composer)
166+
* See the file examples/legacy.php for more information.
131167

132168
#### :zap: Step 3: Enjoy ! Your website is now faster than flash !
133169
For curious developpers, there is a lot of others available examples [here](https://github.com/khoaofgod/phpFastCache/tree/final/examples).
134170

135171
#### :boom: phpFastCache support
136-
Found an issue or had an idea ? Come [here](https://github.com/PHPSocialNetwork/phpfastcache/issues) and let you know !
172+
Found an issue or had an idea ? Come [here](https://github.com/PHPSocialNetwork/phpfastcache/issues) and let us know !

V5-ROADMAP.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
### phpFastCache V5 Roadmap
2+
3+
- [x] Refactoring driver to be psr6 compliant
4+
- [x] Rewrite examples by drivers
5+
- [x] Rewrite examples for complex setups
6+
- [x] Rewrite examples for non-composer users
7+
- [x] Re-implement standalone Autoload for non-composer user
8+
- [x] Rewrite examples for ssdb lib
9+
- [x] Rewrite Readme
10+
- [x] Rewrite tests
11+
- [x] Rewrite stats method to be implemented in a driverStatistic() object, not a breaking change due to ArrayAccess use, but array use is deprecated
12+
- [x] Re-implement tags features (will be the replacement of global search)
13+
- [x] Re-implement [in|de]crement methods in ExtendedCacheItemInterface
14+
- [x] Implement [a|pre]pend methods in ExtendedCacheItemInterface
15+
- [x] Re-implement touch method in ExtendedCacheItemInterface: deprecated in profit CacheItemInterface::expiresAfter()
16+
- [x] Implement MongoDb Driver
17+
- [x] Implement CouchBase Driver
18+
- [x] Implement Dev Driver (return null/bool everywhere for development purpose)
19+
- [x] Implement advanced tags features: incrementByTag(s), decrementByTag(s), appendByTag(s), prependByTag(s), expiresAfterByTag(s)
20+
- [x] Final code review + psr2 checks + psr-6 null value as legitimates value.
21+
- [x] Testing fallback option
22+
- [x] Rewrite Wiki
23+
- [ ] Check Wincache driver in real Windows env (and not in VM)

bin/ci/install_dependencies.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
composer self-update;
4+
composer update;

bin/stubs/leveldb/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Please see: https://github.com/reeze/php-leveldb for more documentation

0 commit comments

Comments
 (0)