PHP Classes

PHP Fast Cache: Store and get data from several cache containers

Recommend this page to a friend!
  Info   Example   Screenshots   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 747 All time: 4,490 This week: 41Up
Version License PHP version Categories
php-fast-cache 624Freeware5.3PHP 5, Cache
Collaborate with this project 

Author

phpfastcache - github.com

Description

This class can store and get data from several cache containers.

It can store the value of a variable of any type in one of several supported cache storage container.

Currently it supports cache containers like: files, SQLite databases using PDO, Memcached, XCache, APC and WinCache.

Each cache entry is associated to a name, so it can retrieved using the same name until the cache expiry time is not reached.

The class can also check if a cache entry exists, increment or decrement cache values, delete given cache entries and clean all cache entries.

Picture of Khoa Bui
  Performance   Level  

 

Example

<?php
include("php_fast_cache.php");
phpFastCache::$storage = "auto";

// ready ?
// check in case first

$content = phpFastCache::get("keyword1");

if(
$content == null) {
   
// for testing
   
echo "This is not caching, page is render with lot queires and slow speed <br>";
   
// do what you want, like get content from cURL | API | mySQL Query and return result to $content
   
$content = file_get_contents("http://www.phpfastcache.com/testing.php");

   
// rewrite cache for other request in 5 seconds
   
phpFastCache::set("keyword1",$content,5);
} else {
   
// use cache
    // node
   
echo "THIS TIME USE CACHE, FAST! <br>";
}

echo
"TRY F5 to refesh the page to see new SPEED with Cache!<br>";
echo
$content;


Details

Code Climate Build Status Latest Stable Version Total Downloads License

Simple Yet Powerful PHP Caching Class

More information at http://www.phpfastcache.com One Class uses for All Cache. You don't need to rewrite your code many times again.

Supported: SSDB, Redis, Predis, Cookie, Files, MemCache, MemCached, APC, WinCache, X-Cache, PDO with SQLite

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

use phpFastCache\CacheManager;

// Default value: is "phpfastcache" (fastest), you can change to "normal" or "memory" (fast)
CacheManager::CachingMethod("normal");

// Recommend: use phpfastcache to reduce files I/O & CPU Load, Memcached missing hits, and make redis and other connections become faster.
// 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
// In bad situation, use "normal" as traditional caching method

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 usefull APIS:

  • get($keyword) // The getter, obviously, return your cache object
  • set($keyword, $something_your_want_to_cache, $time_as_second = 0) // The setter, for those who missed it, put 0 meant cache it forever
  • delete($keyword) // For removing a cached thing
  • clean() // Allow you to completely empty the cache and restart from the beginning
  • touch($keyword, $time_you_want_to_extend) // Allow you to extends the lifetime of an entry without altering the value
  • increment($keyword, $step = 1) // For integer that we can count on
  • decrement($keyword, $step = 1) // Redundant joke...
  • search($string_or_regex, $search_in_value = false | true) // Allow you to perform some search on the cache index
  • isExisting($keyword) // Check if your cache entry exists, it is the equivalent of isset()
  • stats() // Return the cache statistics, useful for checking disk space used by the cache etc.

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

As Fast To Implement As Opening a Beer

:thumbsup: Step 1: Include phpFastCache in your project with composer:

composer require phpFastCache/phpFastCache

:construction: Step 2: Setup your website code to implements phpFastCache bits (With Composer)

use phpFastCache\CacheManager;

// require_once ('vendor/autoload.php');

$cache = CacheManager::Files();

// $cache = CacheManager::Memcached();
// phpFastCache supported: SSDB, Redis, Predis, Cookie, Files, MemCache, MemCached, APC, WinCache, XCache, SQLite
// $cache = CacheManager::getInstance("auto", $config);
// $cache = CacheManager::getInstance("memcached", $server_config);

/
 * Try to get $products from Caching First
 * product_page is "identity keyword";
 */
$key = "product_page";
$products = $cache->get($key);

if (is_null($products)) {
    $products = "DB QUERIES | FUNCTION_GET_PRODUCTS | ARRAY | STRING | OBJECTS";
    // Write products to Cache in 10 minutes with same keyword
    $cache->set($key, $products, 600);

    echo " --> NO CACHE ---> DB | Func | API RUN FIRST TIME ---> ";

} else {
    echo " --> USE CACHE --> SERV 10,000+ Visitors FROM CACHE ---> ";
}

/
 * use your products here or return it;
 */
echo $products;

:floppy_disk: Legacy / Lazy Method (Without Composer)

// In your config files
// require_once ('phpFastCache/src/autoload.php');

use phpFastCache\CacheManager;

// $cache = $cache = CacheManager::Files();
// $cache = phpFastCache();
// $cache = phpFastCache("files");
// $cache = phpFastCache("memcached");

/
 * Try to get $products from Caching First
 * product_page is "identity keyword";
 */
$key = "product_page";
// $products = $cache->get($key);
$products = CacheManager::get($key);
// CacheManager::set() , ::touch ::increment ::search ..etc, work same way without create new instance

// yet it's the same as autoload

:zap: Step 3: Enjoy ! Your website is now faster than flash !

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

:boom: phpFastCache support

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


Screenshots (1)  
  • screen
  Files folder image Files (346)  
File Role Description
Files folder imagedocs (2 files)
Files folder imageexamples (17 files, 1 directory)
Files folder imagesrc (1 file, 1 directory)
Files folder imagetests (3 files)
Plain text file php_fast_cache.php Class Main Cache File. Revision 621
Accessible without login Plain text file example.php Example Example
Accessible without login Plain text file .codeclimate.yml Doc. Documentation
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file CNAME Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login HTML file Detect_Real_IP.html Example Detect Real IP Address
Accessible without login Plain text file README.md Data Auxiliary data
Accessible without login Plain text file readme.txt Doc. Read it first
Accessible without login Plain text file testing.php Example Testing Function Cache

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 98%
Total:747
This week:0
All time:4,490
This week:41Up
User Comments (1)
GOOOOOOOOOOOOOOODDDD!!!!!!!!!! )))))
10 years ago (????????? ???????????)
80%StarStarStarStarStar