Giter Site home page Giter Site logo

vzool / phpfastcache Goto Github PK

View Code? Open in Web Editor NEW

This project forked from phpsocialnetwork/phpfastcache

0.0 2.0 0.0 18.69 MB

The PHP high-performance object caching system ever. phpFastCache is a high-performance, distributed object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. phpFastCache dropped the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful

Home Page: http://www.phpfastcache.com

Shell 0.03% PHP 99.91% ApacheConf 0.02% HTML 0.04%

phpfastcache's Introduction

Code Climate Scrutinizer Code Quality Build Status Latest Stable Version Total Downloads Dependency Status License Coding Standards

โ— V4 USERS, PLEASE SEE THE README !! THE V5 IS OFFICIALY OUT !! YOUR CODE NEEDS TO BE REWRITTEN โ—


Simple Yet Powerful PHP Caching Class

More information in Wiki One Class uses for All Cache. You don't need to rewrite your code many times again.

Supported drivers at this day *

๐Ÿ’ก Feel free to propose a driver by making a new Pull Request, they are welcome !

Regular drivers High performances drivers Development driver
Apc(u) CouchBase Devnull
Cookie Mongodb Devfalse
Files Predis Devtrue
Leveldb Redis
Memcache(d) Ssdb
Sqlite Zend Memory Cache
Wincache
Xcache
Zend Disk Cache

* Driver descriptions available in DOCS/DRIVERS.md

Symfony developers are not forgotten !

Starting of the v5, phpFastCache comes with a Symfony Bundle. He's fresh, so feel free to report any bug or contribute to the code using pull requests.


Not a "Traditional" Caching

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. 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. However, some time you still want to use traditional caching, we support them too.

use phpFastCache\CacheManager;

CacheManager::getInstance('files', $config);
// An alternative exists:
CacheManager::Files($config);

Reduce Database Calls

Your website have 10,000 visitors who are online, and your dynamic page have to send 10,000 same queries to database on every page load. With phpFastCache, your page only send 1 query to DB, and use the cache to serve 9,999 other visitors.


Rich Development API

phpFastCache offers you a lot of useful APIs:

Item API

  • getKey() // Return the item identifier (key)
  • get() // The getter, obviously, return your cache object
  • set($value) // The setter, for those who missed it, put 0 meant cache it forever
  • expiresAfter($ttl) // Allow you to extends the lifetime of an entry without altering the value (formerly known as touch())
  • expiresAt($expiration) // Sets the expiration time for this cache item (as a DateTimeInterface object)
  • increment($step = 1) // For integer that we can count on
  • decrement($step = 1) // Redundant joke...
  • append($data) // Append data to a string or an array (push)
  • prepend($data) // Prepend data to a string or an array (unshift)
  • isHit() // Check if your cache entry exists and is still valid, it is the equivalent of isset()
  • isExpired() // Check if your cache entry is expired
  • getTtl() // Get the remaining Time To Live as an integer
  • getExpirationDate() // Get the expiration date as a Datetime object
  • addTag($tagName) // Add a tag
  • addTags(array $tagNames) // Add many tags
  • setTags(array $tags) // Set some tags
  • getTags() // Get the tags
  • getTagsAsString($separator = ', ') // Get the data a string separated by $separator
  • removeTag($tagName) // Remove a tag
  • removeTags(array $tagNames) // Remove some tags
  • getDataAsJsonString()// Return the data as a well-formatted json string

ItemPool API

  • getItem($key) // Retrieve an item and returns an empty item if not found
  • getItems(array $keys) // Retrieve one or more item and returns an array of items
  • getItemsAsJsonString(array $keys) // Returns A json string that represents an array of items
  • hasItem($key) // Tests if an item exists
  • deleteItem($key) // Delete an item
  • deleteItems(array $keys) // Delete one or more items
  • save(CacheItemInterface $item) // Persists a cache item immediately
  • saveDeferred(CacheItemInterface $item); // Sets a cache item to be persisted later
  • commit(); // Persists any deferred cache items
  • clear() // Allow you to completely empty the cache and restart from the beginning
  • getStats() // Return the cache statistics as an object, useful for checking disk space used by the cache etc.
  • getItemsByTag($tagName) // Return items by a tag
  • getItemsByTags(array $tagNames) // Return items by some tags
  • getItemsByTagsAsJsonString(array $tagNames) // Returns A json string that represents an array of items by tags-based
  • deleteItemsByTag($tagName) // Delete items by a tag
  • deleteItemsByTags(array $tagNames) // Delete items by some tags
  • 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
  • detachItem($item) // Detach an item from the pool
  • detachAllItems($item) // Detach all items from the pool
  • attachItem($item) // (Re-)attach an item to the pool
  • isAttached($item) // Verify if an item is (still) attached

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


As Fast To Implement As Opening a Beer

๐Ÿ‘ Step 1: Include phpFastCache in your project with composer:

composer require phpFastCache/phpFastCache

๐Ÿšง Step 2: Setup your website code to implements phpFastCache bits (With Composer)

use phpFastCache\CacheManager;

// Setup File Path on your config files
CacheManager::setup(array(
    "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 prints 'First product'
}

/**
 * use your products here or return it;
 */
echo implode('<br />', $CachedString->get());// Will echo your product list
๐Ÿ’พ Legacy / Lazy Method (Without Composer)
  • See the file examples/legacy.php for more information.

โšก Step 3: Enjoy ! Your website is now faster than flash !

For curious developpers, there is a lot of others available examples here.

๐Ÿ’ฅ phpFastCache support

Found an issue or had an idea ? Come here and let us know !

phpfastcache's People

Contributors

geolim4 avatar khoaofgod avatar hammermaps avatar bfintal avatar uprel avatar dongnan avatar saiful avatar westy92 avatar chaegumi avatar lemark0 avatar fbonzon avatar likemarx avatar nigrosimone avatar stormopl avatar sigjlr avatar sfriel avatar r0b- avatar olamedia avatar nikmauro avatar majiy avatar kantholy avatar e3betht avatar vincent avatar tobsn avatar tilluhlig avatar remowashere avatar n-i-m-a avatar mike27cubes avatar mipapo avatar lukeb avatar

Watchers

Abdelaziz Elrashed avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.