Skip to content

Commit 23c54c1

Browse files
authored
Merge pull request #455 from Geolim4/final
Merge branch 'v6' into final
2 parents 7b9beb1 + 59665e9 commit 23c54c1

File tree

503 files changed

+59734
-1998
lines changed

Some content is hidden

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

503 files changed

+59734
-1998
lines changed

.travis.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@ language: php
1414

1515
services:
1616
- memcached
17-
# - redis-server
17+
- redis-server
18+
- couchdb
1819
before_script:
1920
- |
2021
if [[ $TRAVIS_PHP_VERSION = "hhv"* ]]; then
21-
cat var/php/conf/phpfastcache.ini >> /etc/hhvm/php.ini
22+
cat bin/ci/php-phpfastcache.ini >> /etc/hhvm/php.ini
2223
else
23-
phpenv config-add var/php/conf/phpfastcache.ini
24+
phpenv config-add bin/ci/php-phpfastcache.ini
2425
fi
2526
2627
php:
2728
# - 5.3
2829
# - 5.4
29-
- 5.5
30+
# - 5.5
3031
- 5.6
3132
- 7.0
3233
- nightly

README.md

Lines changed: 136 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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)
1+
[![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) [![Latest Stable Version](http://img.shields.io/packagist/v/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) [![Coding Standards](https://img.shields.io/badge/CI-PSR6-orange.svg)](https://github.com/php-fig/cache) [![Coding Standards](https://img.shields.io/badge/CS-PSR16-orange.svg)](https://github.com/php-fig/simple-cache)
2+
[![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)
23

3-
:exclamation: V4 USERS, PLEASE SEE THE README !! V5 IS OFFICIALY OUT !! YOUR CODE NEEDS TO BE [REWRITTEN](https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV4%5D-Migrating-your-code-to-the-V5) :exclamation:
4+
:exclamation: V6 USERS, PLEASE NOTE THAT THE V6 REQUIRES PHP 5.6 AT LEAST :exclamation:
45

56
---------------------------
67
Simple Yet Powerful PHP Caching Class
@@ -12,17 +13,17 @@ One Class uses for All Cache. You don't need to rewrite your code many times aga
1213
### Supported drivers at this day *
1314
:bulb: Feel free to propose a driver by making a new **Pull Request**, they are welcome !
1415

15-
| Regular drivers | High performances drivers | Development driver |
16-
|--------------------|---------------------------|--------------------|
17-
| `Apc(u)` | `CouchBase` | `Devnull` |
18-
| `Cookie` | `Mongodb` | `Devfalse` |
19-
| `Files` | `Predis` | `Devtrue` |
20-
| `Leveldb` | `Redis` | |
21-
| `Memcache(d)` | `Ssdb` | |
22-
| `Sqlite` | `Zend Memory Cache` | |
23-
| `Wincache` | | |
24-
| `Xcache` | | |
25-
| `Zend Disk Cache` | | |
16+
| Regular drivers | High performances drivers | Development drivers |
17+
|--------------------|---------------------------|---------------------|
18+
| `Apc(u)` | `Cassandra` | `Devnull` |
19+
| `Cookie` | `CouchBase` | `Devfalse` |
20+
| `Files` | `Couchdb` | `Devtrue` |
21+
| `Leveldb` | `Mongodb` | `Memstatic` |
22+
| `Memcache(d)` | `Predis` | |
23+
| `Sqlite` | `Redis` | |
24+
| `Wincache` | `Ssdb` | |
25+
| `Xcache` | `Zend Memory Cache` | |
26+
| `Zend Disk Cache` | | |
2627

2728
\* Driver descriptions available in DOCS/DRIVERS.md
2829

@@ -32,7 +33,6 @@ It's fresh, so feel free to report any bug or contribute to the project using pu
3233

3334
Also a [Drupal 8 Module](https://github.com/PHPSocialNetwork/phpfastcache-drupal) is currently in development, add it to your starred projects to get notified of the first public release.
3435

35-
3636
---------------------------
3737
Not a "Traditional" Caching
3838
---------------------------
@@ -66,7 +66,7 @@ phpFastCache offers you a lot of useful APIs:
6666
- getKey() // Returns the item identifier (key)
6767
- get() // The getter, obviously, returns your cache object
6868
- set($value) // The setter, for those who missed it, putting 0 means cache it forever
69-
- expiresAfter($ttl) // Allow you to extend the lifetime of an entry without altering its value (formerly known as touch())
69+
- expiresAfter($ttl) // Allows you to extends the lifetime of an entry without altering its value (formerly known as touch())
7070
- expiresAt($expiration) // Sets the expiration time for this cache item (as a DateTimeInterface object)
7171
- increment($step = 1) // To allow us to count on an integer item
7272
- decrement($step = 1) // Redundant joke...
@@ -82,40 +82,146 @@ phpFastCache offers you a lot of useful APIs:
8282
- getTags() // Gets the tags
8383
- getTagsAsString($separator = ', ') // Gets the data as a string separated by $separator
8484
- removeTag($tagName) // Removes a tag
85-
- removeTags(array $tagNames) // Removes some tags
86-
- getDataAsJsonString()// Returns the data as a well-formatted json string
85+
- removeTags(array $tagNames) // Removes multiple tags
86+
- getDataAsJsonString()// Return the data as a well-formatted json string
87+
- setExpirationDate() // Alias of expireAt() (for more code logic)
88+
- getCreationDate() // Gets the creation date for this cache item (as a DateTimeInterface object) *
89+
- getModificationDate() // Gets the modification date for this cache item (as a DateTimeInterface object) *
90+
- setCreationDate($expiration) // Sets the creation date for this cache item (as a DateTimeInterface object) *
91+
- setModificationDate($expiration) // Sets the modification date for this cache item (as a DateTimeInterface object) *
92+
- setEventManager($evtMngr) // Sets the event manager
93+
94+
\* Require configuration directive "itemDetailedDate" to be enabled
8795

8896
### ItemPool API
8997
- getItem($key) // Retrieves an item and returns an empty item if not found
90-
- getItems(array $keys) // Retrieves one or more items and returns an array of items
91-
- getItemsAsJsonString(array $keys) // Returns a json string that represents an array of items
98+
- getItems(array $keys) // Retrieves one or more item and returns an array of items
99+
- getItemsAsJsonString(array $keys) // Returns A json string that represents an array of items
92100
- hasItem($key) // Tests if an item exists
93101
- deleteItem($key) // Deletes an item
94102
- deleteItems(array $keys) // Deletes one or more items
95103
- save(CacheItemInterface $item) // Persists a cache item immediately
104+
- saveMultiple(...$items) // Persists multiple cache items immediately
96105
- saveDeferred(CacheItemInterface $item); // Sets a cache item to be persisted later
97106
- commit(); // Persists any deferred cache items
98-
- clear() // Allows you to completely empty the cache
107+
- clear() // Allows you to completely empty the cache and restart from the beginning
108+
- getHelp() // Provides a very basic help for a specific driver
99109
- getStats() // Returns the cache statistics as an object, useful for checking disk space used by the cache etc.
100110
- getItemsByTag($tagName) // Returns items by a tag
101-
- getItemsByTags(array $tagNames) // Returns items by multiple tags
102-
- getItemsByTagsAsJsonString(array $tagNames) // Returns a json string that represents an array of items corresponding to given tags
111+
- getItemsByTags(array $tagNames) // Returns items by one of multiple tag names
112+
- getItemsByTagsAll(array $tagNames) // Returns items by all of multiple tag names
113+
- getItemsByTagsAsJsonString(array $tagNames) // Returns A json string that represents an array of items corresponding to given tags
103114
- deleteItemsByTag($tagName) // Deletes items by a tag
104-
- deleteItemsByTags(array $tagNames) // Deletes items by multiple tags
115+
- deleteItemsByTags(array $tagNames) // Deletes items by one of multiple tag names
116+
- deleteItemsByTagsAll(array $tagNames) // Deletes items by all of multiple tag names
105117
- incrementItemsByTag($tagName, $step = 1) // Increments items by a tag
106-
- incrementItemsByTags(array $tagNames, $step = 1) // Increments items by multiple tags
118+
- incrementItemsByTags(array $tagNames, $step = 1) // Increments items by one of multiple tag names
119+
- incrementItemsByTagsAll(array $tagNames, $step = 1) // Increments items by all of multiple tag names
107120
- decrementItemsByTag($tagName, $step = 1) // Decrements items by a tag
108-
- decrementItemsByTags(array $tagNames, $step = 1) // Decrements items by multiple tags
121+
- decrementItemsByTags(array $tagNames, $step = 1) // Decrements items by one of multiple tag names
122+
- decrementItemsByTagsAll(array $tagNames, $step = 1) // Decrements items by all of multiple tag names
109123
- appendItemsByTag($tagName, $data) // Appends items by a tag
110-
- appendItemsByTags(array $tagNames, $data) // Appends items by multiple tags
124+
- appendItemsByTags(array $tagNames, $data) // Appends items by one of multiple tag names
125+
- appendItemsByTagsAll(array $tagNames, $data) // Appends items by all of multiple tag names
111126
- prependItemsByTag($tagName, $data) // Prepends items by a tag
112-
- prependItemsByTags(array $tagNames, $data) // Prepends items by multiple tags
127+
- prependItemsByTags(array $tagNames, $data) // Prepends items by one of multiple tag names
128+
- prependItemsByTagsAll(array $tagNames, $data) // Prepends items by all of multiple tag names
113129
- detachItem($item) // Detaches an item from the pool
114130
- detachAllItems($item) // Detaches all items from the pool
115131
- attachItem($item) // (Re-)attaches an item to the pool
116-
- isAttached($item) // Verifies if an item is (still) attached
132+
- isAttached($item) // Verify if an item is (still) attached
133+
- setEventManager(EventManager $evtMngr) // Sets the event manager
134+
135+
It also supports multiple calls, Tagging, Setup Folder for caching. Look at our examples folders for more information.
136+
137+
---------------------------
138+
Want to keep it simple ?
139+
---------------------------
140+
:sweat_smile: Good news, as of the V6, a Psr16 adapter is provided to keep the cache simplest using very basic getters/setters:
141+
142+
- get($key, $default = null);
143+
- set($key, $value, $ttl = null);
144+
- delete($key);
145+
- clear();
146+
- getMultiple($keys, $default = null);
147+
- setMultiple($values, $ttl = null);
148+
- deleteMultiple($keys);
149+
- has($key);
150+
151+
Basic usage:
152+
```php
153+
use phpFastCache\Helper\Psr16Adapter;
154+
155+
$Psr16Adapter = new Psr16Adapter($defaultDriver);
156+
157+
if(!$Psr16Adapter->has('test-key')){
158+
// Setter action
159+
$data = 'lorem ipsum';
160+
$Psr16Adapter->set('test-key', 'lorem ipsum', 300);// 5 minutes
161+
}else{
162+
// Getter action
163+
$data = $Psr16Adapter->get('test-key');
164+
}
165+
166+
167+
/**
168+
* Do your stuff with $data
169+
*/
170+
```
171+
172+
Internally, the Psr16 adapter calls the PhpFastCache Api via the cache manager.
173+
174+
---------------------------
175+
Introducing to events
176+
---------------------------
177+
178+
:mega: As of the V6, PhpFastCache provides an event mechanism.
179+
You can subscribe to an event by passing a Closure to an active event:
180+
181+
```php
182+
use phpFastCache\EventManager;
183+
184+
/**
185+
* Bind the event callback
186+
*/
187+
EventManager::getInstance()->onCacheGetItem(function(ExtendedCacheItemPoolInterface $itemPool, ExtendedCacheItemInterface $item){
188+
$item->set('[HACKED BY EVENT] ' . $item->get());
189+
});
190+
191+
```
192+
193+
An event callback can get unbind but you MUST provide a name to the callback previously:
194+
195+
```php
196+
use phpFastCache\EventManager;
197+
198+
/**
199+
* Bind the event callback
200+
*/
201+
EventManager::getInstance()->onCacheGetItem(function(ExtendedCacheItemPoolInterface $itemPool, ExtendedCacheItemInterface $item){
202+
$item->set('[HACKED BY EVENT] ' . $item->get());
203+
}, 'myCallbackName');
204+
205+
206+
/**
207+
* Unbind the event callback
208+
*/
209+
EventManager::getInstance()->unbindEventCallback('onCacheGetItem', 'myCallbackName');
210+
211+
```
212+
213+
More information about the implementation and the events available on the [Wiki](https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV6%5D-Introducing-to-events)
214+
215+
---------------------------
216+
Introducing new helpers
217+
---------------------------
218+
:books: As of the V6, PhpFastCache provides some helpers to make your code easier.
219+
220+
- The [ActOnAll Helper](https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV6%CB%96%5D-Act-on-all-instances) to help you to act on multiple instance at once.
221+
- The [CacheConditional Helper](https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV6%CB%96%5D-Cache-Conditional) to help you to make the basic conditional statement more easier.
222+
- The [Psr16 adapter](https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV6%CB%96%5D-Psr16-adapter) to keep it simple as explained above.
117223

118-
It also supports Multiple calls, Tagging, Setup Folder for caching. Look at our examples folders for more information.
224+
May more will come in the future, feel free to contribute !
119225

120226
---------------------------
121227
As Fast To Implement As Opening a Beer
@@ -175,7 +281,7 @@ echo implode('<br />', $CachedString->get());// Will echo your product list
175281
```
176282

177283
##### :floppy_disk: Legacy / Lazy Method (Without Composer)
178-
* See the file examples/legacy.php for more information.
284+
* See the file examples/withoutComposer.php for more information.
179285

180286
#### :zap: Step 3: Enjoy ! Your website is now faster than lightning !
181287
For curious developpers, there is a lot of other examples available [here](https://github.com/PHPSocialNetwork/phpfastcache/tree/final/examples).

bin/ci/install_dependencies.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
22

33
composer self-update;
4-
composer update;
4+
composer install --ignore-platform-reqs;
5+
composer require "phpfastcache/couchdb:~1.0.0" "phpfastcache/phpssdb:~1.0.0" "predis/predis:~1.1.0" "mongodb/mongodb:^1.1" --ignore-platform-reqs;

bin/ci/php-phpfastcache.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
; Adding required extensions for tests
2+
extension="memcached.so"
3+
extension="redis.so"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The MIT License (MIT)
2+
3+
Copyright (c) 2016 PHP Framework Interoperability Group
4+
5+
> Permission is hereby granted, free of charge, to any person obtaining a copy
6+
> of this software and associated documentation files (the "Software"), to deal
7+
> in the Software without restriction, including without limitation the rights
8+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
> copies of the Software, and to permit persons to whom the Software is
10+
> furnished to do so, subject to the following conditions:
11+
>
12+
> The above copyright notice and this permission notice shall be included in
13+
> all copies or substantial portions of the Software.
14+
>
15+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
> THE SOFTWARE.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
PHP FIG Simple Cache PSR
2+
========================
3+
4+
This repository holds all interfaces related to PSR-16.
5+
6+
Note that this is not a cache implementation of its own. It is merely an interface that describes a cache implementation. See [the specification](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-16-simple-cache.md) for more details.
7+
8+
You can find implementations of the specification by looking for packages providing the [psr/simple-cache-implementation](https://packagist.org/providers/psr/simple-cache-implementation) virtual package.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "psr/simple-cache",
3+
"description": "Common interfaces for simple caching",
4+
"keywords": ["psr", "psr-16", "cache", "simple-cache", "caching"],
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "PHP-FIG",
9+
"homepage": "http://www.php-fig.org/"
10+
}
11+
],
12+
"require": {
13+
"php": ">=5.3.0"
14+
},
15+
"autoload": {
16+
"psr-4": {
17+
"Psr\\SimpleCache\\": "src/"
18+
}
19+
},
20+
"extra": {
21+
"branch-alias": {
22+
"dev-master": "1.0.x-dev"
23+
}
24+
}
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Psr\SimpleCache;
4+
5+
/**
6+
* Interface used for all types of exceptions thrown by the implementing library.
7+
*/
8+
interface CacheException
9+
{
10+
}

0 commit comments

Comments
 (0)