|
|
6 years ago | |
|---|---|---|
| .. | ||
| .github | 6 years ago | |
| bin | 6 years ago | |
| docs | 6 years ago | |
| src | 6 years ago | |
| tests | 6 years ago | |
| .codeclimate.yml | 6 years ago | |
| .scrutinizer.yml | 6 years ago | |
| .travis.yml | 6 years ago | |
| CHANGELOG.md | 6 years ago | |
| CNAME | 6 years ago | |
| CODE_OF_CONDUCT.md | 6 years ago | |
| LICENCE | 6 years ago | |
| README.md | 6 years ago | |
| composer.json | 6 years ago | |
| composer.lock | 6 years ago | |
:exclamation: V6 USERS, PLEASE NOTE THAT THE V6 REQUIRES PHP 5.6 AT LEAST :exclamation:\ Also please be aware that the V7 was released on the 01 june 2018, therefore you should check\ your dependencies constraints as this release is absolutely not compatible with the current (V6)
More information in Wiki One Class uses for All Cache. You don't need to rewrite your code many times again.
:bulb: Feel free to propose a driver by making a new Pull Request, they are welcome !
| Regular drivers | High performances drivers | Development drivers |
|---|---|---|
Apc(u) |
Cassandra |
Devnull |
Cookie |
CouchBase |
Devfalse |
Files |
Couchdb |
Devtrue |
Leveldb |
Mongodb |
Memstatic |
Memcache(d) |
Predis |
|
Sqlite |
Redis |
|
Wincache |
Ssdb |
|
Xcache |
Zend Memory Cache |
|
Zend Disk Cache |
* Driver descriptions available in DOCS/DRIVERS.md
Starting with v5, phpFastCache comes with a Symfony Bundle. It's fresh, so feel free to report any bug or contribute to the project using pull requests.
Also a Drupal 8 Module is currently in development, add it to your starred projects to get notified of the first public release.
phpFastCache is not like the traditional caching methods which keep reading and writing to files, sqlite or keeping open massive amounts of connections to memcache, redis, mongodb... Also, when you use Memcache / Memcached, your miss hits will be reduced. Different from the usual caching methods you'll find everywhere on the internet, the phpFastCache library reduces high I/O load, and is faster than the traditional caching methods by at least ~7 times. However, when you still want to use traditional caching methods, we support them too.
use phpFastCache\CacheManager;
CacheManager::getInstance('files', $config);
// An alternative exists:
CacheManager::Files($config);
Your website has 10,000 visitors who are online, and your dynamic page has to send 10,000 times the same queries to database on every page load. With phpFastCache, your page only sends 1 query to your DB, and uses the cache to serve the 9,999 other visitors.
phpFastCache offers you a lot of useful APIs:
* Require configuration directive "itemDetailedDate" to be enabled
It also supports multiple calls, Tagging, Setup Folder for caching. Look at our examples folders for more information.
:sweat_smile: Good news, as of the V6, a Psr16 adapter is provided to keep the cache simplest using very basic getters/setters:
Basic usage:
use phpFastCache\Helper\Psr16Adapter;
$Psr16Adapter = new Psr16Adapter($defaultDriver);
if(!$Psr16Adapter->has('test-key')){
// Setter action
$data = 'lorem ipsum';
$Psr16Adapter->set('test-key', 'lorem ipsum', 300);// 5 minutes
}else{
// Getter action
$data = $Psr16Adapter->get('test-key');
}
/**
* Do your stuff with $data
*/
Internally, the Psr16 adapter calls the PhpFastCache Api via the cache manager.
:mega: As of the V6, PhpFastCache provides an event mechanism. You can subscribe to an event by passing a Closure to an active event:
use phpFastCache\EventManager;
/**
* Bind the event callback
*/
EventManager::getInstance()->onCacheGetItem(function(ExtendedCacheItemPoolInterface $itemPool, ExtendedCacheItemInterface $item){
$item->set('[HACKED BY EVENT] ' . $item->get());
});
An event callback can get unbind but you MUST provide a name to the callback previously:
use phpFastCache\EventManager;
/**
* Bind the event callback
*/
EventManager::getInstance()->onCacheGetItem(function(ExtendedCacheItemPoolInterface $itemPool, ExtendedCacheItemInterface $item){
$item->set('[HACKED BY EVENT] ' . $item->get());
}, 'myCallbackName');
/**
* Unbind the event callback
*/
EventManager::getInstance()->unbindEventCallback('onCacheGetItem', 'myCallbackName');
More information about the implementation and the events are available on the Wiki
:books: As of the V6, PhpFastCache provides some helpers to make your code easier.
May more will come in the future, feel free to contribute !
composer require phpFastCache/phpFastCache
use phpFastCache\CacheManager;
// Setup File Path on your config files
CacheManager::setDefaultConfig([
"path" => '/var/www/phpfastcache.com/dev/tmp', // or in windows "C:/tmp/"
]);
// In your class, function, you can call the Cache
$InstanceCache = CacheManager::getInstance('files');
/**
* Try to get $products from Caching First
* product_page is "identity keyword";
*/
$key = "product_page";
$CachedString = $InstanceCache->getItem($key);
$your_product_data = [
'First product',
'Second product',
'Third product'
// etc...
];
if (is_null($CachedString->get())) {
$CachedString->set($your_product_data)->expiresAfter(5);//in seconds, also accepts Datetime
$InstanceCache->save($CachedString); // Save the cache item just like you do with doctrine and entities
echo "FIRST LOAD // WROTE OBJECT TO CACHE // RELOAD THE PAGE AND SEE // ";
echo $CachedString->get();
} else {
echo "READ FROM CACHE // ";
echo $CachedString->get()[0];// Will print 'First product'
}
/**
* use your products here or return them;
*/
echo implode('<br />', $CachedString->get());// Will echo your product list
PhpFastCache provide it's own autoload for legacy implementation. Please see the sample in docs/examples/withoutComposer.php for more information.
For curious developers, there is a lot of other examples available here.
Found an issue or have an idea ? Come here and let us know !