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

Recommend this page to a friend!

  Author  
Picture of Khoa Bui
Name: Khoa Bui <contact>
Classes: 2 packages by
Country: United States United States
Age: 31
All time rank: 900112 in United States United States
Week rank: 259 23 in United States United States


  Detailed description   Download .zip .tar.gz   Install with Composer  
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.

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 !


  Classes of Khoa Bui  >  PHP Fast Cache  >  Download .zip .tar.gz  >  Support forum (1)  >  Blog  >  Latest changes  
Name: PHP Fast Cache
Base name: php-fast-cache
Description: Store and get data from several cache containers
Version: 624
PHP version: 5.3
License: Freeware
All time users: 729 users
All time rank: 4519
Week users: 0 users
Week rank: 211
 
  Groups   Screenshots   User ratings  
  Applications   Related pages   Files  

  Groups  
PHP 5 Classes using PHP 5 specific features View top rated classes
Cache Classes for managing cached pages View top rated classes

  Screenshots  
screen
File Role Description
screen Screen phpfastcache


  User ratings  
Not enough user ratings

  Applications that use this package  
No pages of applications that use this class were specified.

If you know an application of this package, send a message to the author to add a link here.


  Related pages  
Example
Example
GitHub
GitHub

  Files  
File Role Description
docs (2 files)
examples (17 files, 1 directory)
src (1 file, 1 directory)
tests (3 files)
php_fast_cache.php Class Main Cache File. Revision 621
example.php Example Example
.codeclimate.yml Doc. Documentation
.travis.yml Data Auxiliary data
CNAME Data Auxiliary data
composer.json Data Auxiliary data
Detect_Real_IP.html Example Detect Real IP Address
README.md Data Auxiliary data
readme.txt Doc. Read it first
testing.php Example Testing Function Cache

  Files  /  docs  
File Role Description
   CREDITS.txt Doc. Documentation
   LICENCE.txt Doc. Documentation

  Files  /  examples  
File Role Description
legacy_examples (7 files)
   apc.php Class Class source
   cookie.php Class Class source
   files.php Class Class source
   global.setup.php Class Class source
   index.php Class Class source
   LazyMethod.php Class Class source
   memcache.php Class Class source
   memcached.php Class Class source
   predis.php Class Class source
   redis.php Class Class source
   Search.YourCaching.php Class Class source
   sqlite.php Class Class source
   ssdb.php Class Class source
   Tags.YourCaching.php Class Class source
   Testing.php Class Class source
   Unicode.Caching.php Class Class source
   xcache.php Class Class source

  Files  /  examples  /  legacy_examples  
File Role Description
   1.example.php Class Class source
   2.example.php Class Class source
   3.setup.php Class Class source
   4.travel.php Class Class source
   5.functions.php Class Class source
   6.systeminfo.php Class Class source
   readme_legacy.php Class Class source

  Files  /  src  
File Role Description
phpFastCache (1 file, 7 directories)
   autoload.php Class Class source

  Files  /  src  /  phpFastCache  
File Role Description
Core (4 files)
Drivers (13 files)
Exceptions (2 files)
Legacy (1 file)
Plugins (1 file)
Util (1 file)
_extensions (1 file, 1 directory)
   CacheManager.php Class Class source

  Files  /  src  /  phpFastCache  /  Core  
File Role Description
   DriverAbstract.php Class Class source
   DriverInterface.php Class Class source
   phpFastCache.php Class Class source
   phpFastCacheExtensions.php Class Class source

  Files  /  src  /  phpFastCache  /  Drivers  
File Role Description
   apc.php Class Class source
   cookie.php Class Class source
   example.php Class Class source
   files.php Class Class source
   memcache.php Class Class source
   memcached.php Class Class source
   mongodb.php Class Class source
   predis.php Class Class source
   redis.php Class Class source
   sqlite.php Class Class source
   ssdb.php Class Class source
   wincache.php Class Class source
   xcache.php Class Class source

  Files  /  src  /  phpFastCache  /  Exceptions  
File Role Description
   phpFastCacheCoreException.php Class Class source
   phpFastCacheDriverException.php Class Class source

  Files  /  src  /  phpFastCache  /  Legacy  
File Role Description
   aliases.php Class Class source

  Files  /  src  /  phpFastCache  /  Plugins  
File Role Description
   CronClearFiles.php Class Class source

  Files  /  src  /  phpFastCache  /  Util  
File Role Description
   Languages.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  
File Role Description
predis-1.0 (9 files, 2 directories)
   SSDB.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  
File Role Description
examples (15 files)
src (8 files, 14 directories)
   autoload.php Class Class source
   CHANGELOG.md Data Auxiliary data
   composer.json Data Auxiliary data
   CONTRIBUTING.md Data Auxiliary data
   FAQ.md Data Auxiliary data
   LICENSE Data Auxiliary data
   package.ini Data Auxiliary data
   README.md Data Auxiliary data
   VERSION Data Auxiliary data

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  examples  
File Role Description
   custom_cluster_distributor.php Class Class source
   debuggable_connection.php Class Class source
   dispatcher_loop.php Class Class source
   executing_redis_commands.php Class Class source
   key_prefixing.php Class Class source
   lua_scripting_abstraction.php Class Class source
   monitor_consumer.php Class Class source
   pipelining_commands.php Class Class source
   pubsub_consumer.php Class Class source
   redis_collections_iterators.php Class Class source
   replication_complex.php Class Class source
   replication_simple.php Class Class source
   session_handler.php Class Class source
   shared.php Class Class source
   transaction_using_cas.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  
File Role Description
Cluster (4 files, 2 directories)
Collection (1 directory)
Command (155 files, 1 directory)
Configuration (9 files)
Connection (15 files, 1 directory)
Monitor (1 file)
Pipeline (4 files)
Profile (10 files)
Protocol (4 files, 1 directory)
PubSub (3 files)
Replication (1 file)
Response (5 files, 1 directory)
Session (1 file)
Transaction (3 files)
   Autoloader.php Class Class source
   Client.php Class Class source
   ClientContextInterface.php Class Class source
   ClientException.php Class Class source
   ClientInterface.php Class Class source
   CommunicationException.php Class Class source
   NotSupportedException.php Class Class source
   PredisException.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Cluster  
File Role Description
Distributor (4 files)
Hash (2 files)
   ClusterStrategy.php Class Class source
   PredisStrategy.php Class Class source
   RedisStrategy.php Class Class source
   StrategyInterface.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Cluster  /  Distributor  
File Role Description
   DistributorInterface.php Class Class source
   EmptyRingException.php Class Class source
   HashRing.php Class Class source
   KetamaRing.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Cluster  /  Hash  
File Role Description
   CRC16.php Class Class source
   HashGeneratorInterface.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Collection  
File Role Description
Iterator (6 files)

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Collection  /  Iterator  
File Role Description
   CursorBasedIterator.php Class Class source
   HashKey.php Class Class source
   Keyspace.php Class Class source
   ListKey.php Class Class source
   SetKey.php Class Class source
   SortedSetKey.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Command  
File Role Description
Processor (3 files)
   Command.php Class Class source
   CommandInterface.php Class Class source
   ConnectionAuth.php Class Class source
   ConnectionEcho.php Class Class source
   ConnectionPing.php Class Class source
   ConnectionQuit.php Class Class source
   ConnectionSelect.php Class Class source
   HashDelete.php Class Class source
   HashExists.php Class Class source
   HashGet.php Class Class source
   HashGetAll.php Class Class source
   HashGetMultiple.php Class Class source
   HashIncrementBy.php Class Class source
   HashIncrementByFloat.php Class Class source
   HashKeys.php Class Class source
   HashLength.php Class Class source
   HashScan.php Class Class source
   HashSet.php Class Class source
   HashSetMultiple.php Class Class source
   HashSetPreserve.php Class Class source
   HashValues.php Class Class source
   HyperLogLogAdd.php Class Class source
   HyperLogLogCount.php Class Class source
   HyperLogLogMerge.php Class Class source
   KeyDelete.php Class Class source
   KeyDump.php Class Class source
   KeyExists.php Class Class source
   KeyExpire.php Class Class source
   KeyExpireAt.php Class Class source
   KeyKeys.php Class Class source
   KeyMove.php Class Class source
   KeyPersist.php Class Class source
   KeyPreciseExpire.php Class Class source
   KeyPreciseExpireAt.php Class Class source
   KeyPreciseTimeToLive.php Class Class source
   KeyRandom.php Class Class source
   KeyRename.php Class Class source
   KeyRenamePreserve.php Class Class source
   KeyRestore.php Class Class source
   KeyScan.php Class Class source
   KeySort.php Class Class source
   KeyTimeToLive.php Class Class source
   KeyType.php Class Class source
   ListIndex.php Class Class source
   ListInsert.php Class Class source
   ListLength.php Class Class source
   ListPopFirst.php Class Class source
   ListPopFirstBlocking.php Class Class source
   ListPopLast.php Class Class source
   ListPopLastBlocking.php Class Class source
   ListPopLastPushHead.php Class Class source
   ListPopLastPushHeadBlocking.php Class Class source
   ListPushHead.php Class Class source
   ListPushHeadX.php Class Class source
   ListPushTail.php Class Class source
   ListPushTailX.php Class Class source
   ListRange.php Class Class source
   ListRemove.php Class Class source
   ListSet.php Class Class source
   ListTrim.php Class Class source
   PrefixableCommandInterface.php Class Class source
   PubSubPublish.php Class Class source
   PubSubPubsub.php Class Class source
   PubSubSubscribe.php Class Class source
   PubSubSubscribeByPattern.php Class Class source
   PubSubUnsubscribe.php Class Class source
   PubSubUnsubscribeByPattern.php Class Class source
   RawCommand.php Class Class source
   ScriptCommand.php Class Class source
   ServerBackgroundRewriteAOF.php Class Class source
   ServerBackgroundSave.php Class Class source
   ServerClient.php Class Class source
   ServerCommand.php Class Class source
   ServerConfig.php Class Class source
   ServerDatabaseSize.php Class Class source
   ServerEval.php Class Class source
   ServerEvalSHA.php Class Class source
   ServerFlushAll.php Class Class source
   ServerFlushDatabase.php Class Class source
   ServerInfo.php Class Class source
   ServerInfoV26x.php Class Class source
   ServerLastSave.php Class Class source
   ServerMonitor.php Class Class source
   ServerObject.php Class Class source
   ServerSave.php Class Class source
   ServerScript.php Class Class source
   ServerSentinel.php Class Class source
   ServerShutdown.php Class Class source
   ServerSlaveOf.php Class Class source
   ServerSlowlog.php Class Class source
   ServerTime.php Class Class source
   SetAdd.php Class Class source
   SetCardinality.php Class Class source
   SetDifference.php Class Class source
   SetDifferenceStore.php Class Class source
   SetIntersection.php Class Class source
   SetIntersectionStore.php Class Class source
   SetIsMember.php Class Class source
   SetMembers.php Class Class source
   SetMove.php Class Class source
   SetPop.php Class Class source
   SetRandomMember.php Class Class source
   SetRemove.php Class Class source
   SetScan.php Class Class source
   SetUnion.php Class Class source
   SetUnionStore.php Class Class source
   StringAppend.php Class Class source
   StringBitCount.php Class Class source
   StringBitOp.php Class Class source
   StringBitPos.php Class Class source
   StringDecrement.php Class Class source
   StringDecrementBy.php Class Class source
   StringGet.php Class Class source
   StringGetBit.php Class Class source
   StringGetMultiple.php Class Class source
   StringGetRange.php Class Class source
   StringGetSet.php Class Class source
   StringIncrement.php Class Class source
   StringIncrementBy.php Class Class source
   StringIncrementByFloat.php Class Class source
   StringPreciseSetExpire.php Class Class source
   StringSet.php Class Class source
   StringSetBit.php Class Class source
   StringSetExpire.php Class Class source
   StringSetMultiple.php Class Class source
   StringSetMultiplePreserve.php Class Class source
   StringSetPreserve.php Class Class source
   StringSetRange.php Class Class source
   StringStrlen.php Class Class source
   StringSubstr.php Class Class source
   TransactionDiscard.php Class Class source
   TransactionExec.php Class Class source
   TransactionMulti.php Class Class source
   TransactionUnwatch.php Class Class source
   TransactionWatch.php Class Class source
   ZSetAdd.php Class Class source
   ZSetCardinality.php Class Class source
   ZSetCount.php Class Class source
   ZSetIncrementBy.php Class Class source
   ZSetIntersectionStore.php Class Class source
   ZSetLexCount.php Class Class source
   ZSetRange.php Class Class source
   ZSetRangeByLex.php Class Class source
   ZSetRangeByScore.php Class Class source
   ZSetRank.php Class Class source
   ZSetRemove.php Class Class source
   ZSetRemoveRangeByLex.php Class Class source
   ZSetRemoveRangeByRank.php Class Class source
   ZSetRemoveRangeByScore.php Class Class source
   ZSetReverseRange.php Class Class source
   ZSetReverseRangeByScore.php Class Class source
   ZSetReverseRank.php Class Class source
   ZSetScan.php Class Class source
   ZSetScore.php Class Class source
   ZSetUnionStore.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Command  /  Processor  
File Role Description
   KeyPrefixProcessor.php Class Class source
   ProcessorChain.php Class Class source
   ProcessorInterface.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Configuration  
File Role Description
   ClusterOption.php Class Class source
   ConnectionFactoryOption.php Class Class source
   ExceptionsOption.php Class Class source
   OptionInterface.php Class Class source
   Options.php Class Class source
   OptionsInterface.php Class Class source
   PrefixOption.php Class Class source
   ProfileOption.php Class Class source
   ReplicationOption.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Connection  
File Role Description
Aggregate (5 files)
   AbstractConnection.php Class Class source
   AggregateConnectionInterface.php Class Class source
   CompositeConnectionInterface.php Class Class source
   CompositeStreamConnection.php Class Class source
   ConnectionException.php Class Class source
   ConnectionInterface.php Class Class source
   Factory.php Class Class source
   FactoryInterface.php Class Class source
   NodeConnectionInterface.php Class Class source
   Parameters.php Class Class source
   ParametersInterface.php Class Class source
   PhpiredisSocketConnection.php Class Class source
   PhpiredisStreamConnection.php Class Class source
   StreamConnection.php Class Class source
   WebdisConnection.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Connection  /  Aggregate  
File Role Description
   ClusterInterface.php Class Class source
   MasterSlaveReplication.php Class Class source
   PredisCluster.php Class Class source
   RedisCluster.php Class Class source
   ReplicationInterface.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Monitor  
File Role Description
   Consumer.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Pipeline  
File Role Description
   Atomic.php Class Class source
   ConnectionErrorProof.php Class Class source
   FireAndForget.php Class Class source
   Pipeline.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Profile  
File Role Description
   Factory.php Class Class source
   ProfileInterface.php Class Class source
   RedisProfile.php Class Class source
   RedisUnstable.php Class Class source
   RedisVersion200.php Class Class source
   RedisVersion220.php Class Class source
   RedisVersion240.php Class Class source
   RedisVersion260.php Class Class source
   RedisVersion280.php Class Class source
   RedisVersion300.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Protocol  
File Role Description
Text (4 files, 1 directory)
   ProtocolException.php Class Class source
   ProtocolProcessorInterface.php Class Class source
   RequestSerializerInterface.php Class Class source
   ResponseReaderInterface.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Protocol  /  Text  
File Role Description
Handler (7 files)
   CompositeProtocolProcessor.php Class Class source
   ProtocolProcessor.php Class Class source
   RequestSerializer.php Class Class source
   ResponseReader.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Protocol  /  Text  /  Handler  
File Role Description
   BulkResponse.php Class Class source
   ErrorResponse.php Class Class source
   IntegerResponse.php Class Class source
   MultiBulkResponse.php Class Class source
   ResponseHandlerInterface.php Class Class source
   StatusResponse.php Class Class source
   StreamableMultiBulkResponse.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  PubSub  
File Role Description
   AbstractConsumer.php Class Class source
   Consumer.php Class Class source
   DispatcherLoop.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Replication  
File Role Description
   ReplicationStrategy.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Response  
File Role Description
Iterator (3 files)
   Error.php Class Class source
   ErrorInterface.php Class Class source
   ResponseInterface.php Class Class source
   ServerException.php Class Class source
   Status.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Response  /  Iterator  
File Role Description
   MultiBulk.php Class Class source
   MultiBulkIterator.php Class Class source
   MultiBulkTuple.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Session  
File Role Description
   Handler.php Class Class source

  Files  /  src  /  phpFastCache  /  _extensions  /  predis-1.0  /  src  /  Transaction  
File Role Description
   AbortedMultiExecException.php Class Class source
   MultiExec.php Class Class source
   MultiExecState.php Class Class source

  Files  /  tests  
File Role Description
   Autoload.test.php Class Class source
   NewCacheInstance.test.php Class Class source
   SyntaxChecker.test.php Class Class source

Install with Composer - Download all files: php-fast-cache.tar.gz php-fast-cache.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.

For more information send a message to info at phpclasses dot org.