Giter Club home page Giter Club logo

phpsocialnetwork / phpfastcache Goto Github PK

View Code? Open in Web Editor NEW
2.3K 128.0 451.0 21.31 MB

A high-performance backend cache system. It is intended for use in speeding up dynamic web applications by alleviating database load. Well implemented, it can drops the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful.

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

License: MIT License

PHP 99.46% Shell 0.50% Batchfile 0.04%
cache php redis couchbase speed website mongodb cassandra driver memcached

phpfastcache's Introduction

Total Downloads Latest Stable Version PHPSTAN Cache Interface Extended Coding Style Simple Cache Code Climate Scrutinizer Code Quality Build Status Semver compliant License Patreon

โš ๏ธ Please note that the V9 is mostly a PHP 8 type aware update of Phpfastcache with some significant changes !

As the V9 is relatively not compatible with previous versions, please read carefully the migration guide to ensure you the smoothest migration possible. One of the biggest changes is the configuration system which is now an object that replace the primitive array that we used to implement back then. Also, please note that the V9 requires at least PHP 8 or higher to works properly.


Simple Yet Powerful PHP Caching Class

More information in Wiki The simplicity of abstraction: One class for many backend 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 drivers (Core) Cluster-Aggregated drivers (Core)
Apcu (Core)
(APC support removed)
Arangodb (Extension) Devnull FullReplicationCluster
Dynamodb (Extension) Cassandra
(PHP extension is no more maintained by Datastax, might be deprecated in v10)
Devrandom SemiReplicationCluster
Files (Core) CouchBasev3 (Core)
(Will be deprecated as of v10)
Memory
(Previously named Memstatic)
MasterSlaveReplicationCluster
Firestore (Extension) CouchBasev4 (Extension) RandomReplicationCluster
Leveldb (Core) Couchdb (Extension)
Memcache(d) (Core) Mongodb (Extension)
Solr (Extension) Predis (Core)
Sqlite (Core) Ravendb _(Extension)
Wincache (Core)
(Deprecated as of v9.2, will be removed as of v10)
Redis/RedisCluster (Core)
Zend Disk Cache (Core) Ssdb (Core)
Zend Memory Cache (Core)

* Driver descriptions available in DOCS/DRIVERS.md

๐Ÿ†• As of v9.2 a new Couchbase extension has been released: Couchbasev4 Also a new driver extension has been added: Ravendb. The driver will be actively developed in the feature to allow better fine-grained configuration. This new extension is the beginning of a new era for Phpfastcache along with some others:
Many drivers has been moved from the core to their own sub-repository as a standalone extension: Arangodb, Couchdb, Dynamodb, Firestore, Mongodb, Solr.
They can be easily added through composer, ex: composer install phpfastcache/couchbasev4-extension However Couchbasev3 will stay in the core for compatibility reasons but will be deprecated.


Because caching does not mean weaken your code

Phpfastcache has been developed over the years with 3 main goals:

  • Performance: We optimized and still optimize the code to provide you the lightest library as possible
  • Security: Because caching strategies can sometimes comes with unwanted vulnerabilities, we do our best to provide you a sage & strong library as possible
  • Portability: No matter what operating system you're working on, we did our best to provide you the most cross-platform code as possible

Rich Development API

Phpfastcache provides you a lot of useful APIs:

Item API (ExtendedCacheItemInterface)

Method Return Description
addTag($tagName) ExtendedCacheItemInterface Adds a tag
addTags(array $tagNames) ExtendedCacheItemInterface Adds multiple tags
append($data) ExtendedCacheItemInterface Appends data to a string or an array (push)
decrement($step = 1) ExtendedCacheItemInterface Redundant joke...
expiresAfter($ttl) ExtendedCacheItemInterface Allows you to extends the lifetime of an entry without altering its value (formerly known as touch())
expiresAt($expiration) ExtendedCacheItemInterface Sets the expiration time for this cache item (as a DateTimeInterface object)
get() mixed The getter, obviously, returns your cache object
getCreationDate() \DatetimeInterface Gets the creation date for this cache item (as a DateTimeInterface object) *
getDataAsJsonString() string Return the data as a well-formatted json string
getEncodedKey() string Returns the final and internal item identifier (key), generally used for debug purposes
getExpirationDate() ExtendedCacheItemInterface Gets the expiration date as a Datetime object
getKey() string Returns the item identifier (key)
getLength() int Gets the data length if the data is a string, array, or objects that implement \Countable interface.
getModificationDate() \DatetimeInterface Gets the modification date for this cache item (as a DateTimeInterface object) *
getTags() string[] Gets the tags
hasTag(string $tagName) bool Check if the cache item contain one specific tag
hasTags(array $tagNames, int $strategy): bool bool Check if the cache item contain one or more specific tag with optional strategy (default to TAG_STRATEGY_ONE)
isTagged(): bool bool Check if the cache item has at least one tag (v9.2)
getTagsAsString($separator = ', ') string Gets the data as a string separated by $separator
getTtl() int Gets the remaining Time To Live as an integer
increment($step = 1) ExtendedCacheItemInterface To allow us to count on an integer item
isEmpty() bool Checks if the data is empty or not despite the hit/miss status.
isExpired() bool Checks if your cache entry is expired
isHit() bool Checks if your cache entry exists and is still valid, it's the equivalent of isset()
isNull() bool Checks if the data is null or not despite the hit/miss status.
prepend($data) ExtendedCacheItemInterface Prepends data to a string or an array (unshift)
removeTag($tagName) ExtendedCacheItemInterface Removes a tag
removeTags(array $tagNames) ExtendedCacheItemInterface Removes multiple tags
set($value) ExtendedCacheItemInterface The setter, for those who missed it, can be anything except resources or non-serializer object (ex: PDO objects, file pointers, etc).
setCreationDate($expiration) \DatetimeInterface Sets the creation date for this cache item (as a DateTimeInterface object) *
setEventManager($evtMngr) ExtendedCacheItemInterface Sets the event manager
setExpirationDate() ExtendedCacheItemInterface Alias of expireAt() (for more code logic)
setModificationDate($expiration) \DatetimeInterface Sets the modification date for this cache item (as a DateTimeInterface object) *
setTags(array $tags) ExtendedCacheItemInterface Sets multiple tags
* Require configuration directive "itemDetailedDate" to be enabled, else a \LogicException will be thrown

ItemPool API (ExtendedCacheItemPoolInterface)

Methods (By Alphabetic Order) Return Description
appendItemsByTag($tagName, $data) bool Appends items by a tag
appendItemsByTags(array $tagNames, $data) bool Appends items by one of multiple tag names
attachItem($item) void (Re-)attaches an item to the pool
clear() bool Allows you to completely empty the cache and restart from the beginning
commit() bool Persists any deferred cache items
decrementItemsByTag($tagName, $step = 1) bool Decrements items by a tag
decrementItemsByTags(array $tagNames, $step = 1) bool Decrements items by one of multiple tag names
deleteItem($key) bool Deletes an item
deleteItems(array $keys) bool Deletes one or more items
deleteItemsByTag($tagName) bool Deletes items by a tag
deleteItemsByTags(array $tagNames, int $strategy) bool Deletes items by one of multiple tag names
detachItem($item) void Detaches an item from the pool
getConfig() ConfigurationOption Returns the configuration object
getConfigOption($optionName); mixed Returns a configuration value by its key $optionName
getDefaultConfig() ConfigurationOption Returns the default configuration object (not altered by the object instance)
getDriverName() string Returns the current driver name (without the namespace)
getEventManager() EventManagerInterface Gets the event manager
getHelp() string Provides a very basic help for a specific driver
getInstanceId() string Returns the instance ID
getItem($key) ExtendedCacheItemInterface Retrieves an item and returns an empty item if not found
getItems(array $keys) ExtendedCacheItemInterface[] Retrieves one or more item and returns an array of items. As of v9.2 an internal improvement has been made to this method.
getAllItems(string $pattern = '') ExtendedCacheItemInterface[] (v9.2) Retrieves all cache items with a hard limit of 9999 items. Support limited to some drivers
getItemsAsJsonString(array $keys) string Returns A json string that represents an array of items
getItemsByTag($tagName, $strategy) ExtendedCacheItemInterface[] Returns items by a tag
getItemsByTags(array $tagNames, $strategy) ExtendedCacheItemInterface[] Returns items by one of multiple tag names
getItemsByTagsAsJsonString(array $tagNames, $strategy) string Returns A json string that represents an array of items corresponding
getStats() DriverStatistic Returns the cache statistics as an object, useful for checking disk space used by the cache etc.
hasEventManager() bool Check the event manager
hasItem($key) bool Tests if an item exists
incrementItemsByTag($tagName, $step = 1, $strategy) bool Increments items by a tag
incrementItemsByTags(array $tagNames, $step = 1, $strategy) bool Increments items by one of multiple tag names
isAttached($item) bool Verify if an item is (still) attached
prependItemsByTag($tagName, $data, $strategy) bool Prepends items by a tag
prependItemsByTags(array $tagNames, $data, $strategy) bool Prepends items by one of multiple tag names
save(CacheItemInterface $item) bool Persists a cache item immediately
saveDeferred(CacheItemInterface $item) bool Sets a cache item to be persisted later
saveMultiple(...$items) bool Persists multiple cache items immediately
setEventManager(EventManagerInterface $evtMngr) ExtendedCacheItemPoolInterface Sets the event manager

๐Ÿ†• in V8: Multiple strategies ($strategy) are now supported for tagging:

  • TaggableCacheItemPoolInterface::TAG_STRATEGY_ONE allows you to get cache item(s) by at least ONE of the specified matching tag(s). Default behavior.
  • TaggableCacheItemPoolInterface::TAG_STRATEGY_ALL allows you to get cache item(s) by ALL of the specified matching tag(s) (the cache item can have additional tag(s))
  • TaggableCacheItemPoolInterface::TAG_STRATEGY_ONLY allows you to get cache item(s) by ONLY the specified matching tag(s) (the cache item cannot have additional tag(s))

It also supports multiple calls, Tagging, Setup Folder for caching. Look at our examples folders for more information.

Phpfastcache versioning API

Phpfastcache provides a class that gives you basic information about your Phpfastcache installation

  • Get the API version (Item+Pool interface) with Phpfastcache\Api::GetVersion();
  • Get the API changelog (Item+Pool interface) Phpfastcache\Api::getChangelog();
  • Get the Phpfastcache version with Phpfastcache\Api::getPhpfastcacheVersion();
  • Get the Phpfastcache changelog Phpfastcache\Api::getPhpfastcacheChangelog();

Want to keep it simple ?

๐Ÿ˜… Good news, as of the V6, a Psr16 adapter is provided to keep the cache simplest using very basic getters/setters:

  • get($key, $default = null);
  • set($key, $value, $ttl = null);
  • delete($key);
  • clear();
  • getMultiple($keys, $default = null);
  • setMultiple($values, $ttl = null);
  • deleteMultiple($keys);
  • has($key);

Basic usage:

<?php

use Phpfastcache\Helper\Psr16Adapter;

$defaultDriver = 'Files';
$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.


Introducing to events

๐Ÿ“ฃ As of the V6, Phpfastcache provides an event mechanism. You can subscribe to an event by passing a Closure to an active event:

<?php

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:

<?php
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');

๐Ÿ†• As of the V8 you can simply subscribe to every event of Phpfastcache.

More information about the implementation and the events are available on the Wiki


Introducing new helpers

๐Ÿ“š As of the V6, Phpfastcache provides some helpers to make your code easier.

May more will come in the future, feel free to contribute !


Introducing aggregated cluster support

Check out the WIKI to learn how to implement aggregated cache clustering feature.


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 implement the phpFastCache calls (with Composer)

<?php
use Phpfastcache\CacheManager;
use Phpfastcache\Config\ConfigurationOption;

// Setup File Path on your config files
// Please note that as of the V6.1 the "path" config 
// can also be used for Unix sockets (Redis, Memcache, etc)
CacheManager::setDefaultConfig(new ConfigurationOption([
    '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'
     /* ... */
];

if (!$CachedString->isHit()) {
    $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
๐Ÿ’พ Legacy support (Without Composer)

* See the file examples/withoutComposer.php for more information.
โš ๏ธ The legacy autoload will be removed in the next major release โš ๏ธ
Please include Phpfastcache through composer by running composer require phpfastcache/phpfastcache.

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

For curious developers, there is a lot of other examples available here.

๐Ÿ’ฅ Phpfastcache support

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

phpfastcache's People

Contributors

absfarah avatar bfintal avatar bukowskiadam avatar burlesonbrad avatar bylexus avatar chaegumi avatar dongnan avatar fbonzon avatar geolim4 avatar git-webmaster avatar golodnyi avatar hammermaps avatar jfcherng avatar jomisacu avatar khoaofgod avatar landy2005 avatar lemark0 avatar likemarx avatar marcomiltenburg avatar maximiliankresse avatar nigrosimone avatar r0b- avatar remowashere avatar saiful avatar tilluhlig avatar tobsn avatar unryongpark avatar uprel avatar vincent avatar westy92 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phpfastcache's Issues

Schedules for Next Version 2.0

Hi guys

I am gonna make next version 2.0

  • The current one is 1.3 will be keep going improve and fix bugs. I will not remove current version on future, and I will keep develop it as one file / one static class for who is using it.
  • The version 2.0 will on schedule working, and will be publish together with current version.

Reason to plan to 2.0 are:

  • One Class can't handle everything. It makes it
    painful to add a new backend (redis, apcu, tokyotyrant, mongodb, ...) or
    modify an existing one.
  • Need responsability in case you want to keep the possibility to have multiple
    backends.
  • Factory method instead, maybe a singleton method if necessary

In design for phpFastCache in my head right now:

  • Not use static any more;
  • phpfastcache_get(); phpfastcache_set();
  • phpfastcache.php
  • phpfastcache_class/apc.php ; wincache.php ; xcache.php .. etc

It easy to add new class, upgrading, bugs, and easy to save memory when u don't need other class loading.

Any ideas reply at this topic.

Have a question? Feel FREE to post it here

If you have any questions or you need my help, just create a topic here.

I will take care it on couple hours.

You can also skype me: khoaofgod

*** PLEASE do not reply this topic, just create new one ^_^ Thanks, dude.

Error Writable permission!

Hallo Khoafgod...

I am trying phpfascache but I get error "Please re-upload the caching file caching.0777 and chmod it 0777 or Writable permission!"

I am using Mac with Mamp Pro and I have change attribut the caching.0777 writable...
Do you know what exactly my problem?

Thanks

sqlite (auto mode) stats() returns error

When requesting stats() from the cache object, it returns a error that the table caching does not exist.

(line 303 in sqlite.php)

If I comment those line 303 - 307 the stats() keeps returning 0 for each value in the array.

Cache PATH

Helo Khoafgod...

I want to ask about Cache PATH, I have set cache path to another path but it's still in current directory, how to fixed it?
Example :
phpFastCache::$path = SRV_ROOT.CACHE;// absolute path

I look at Line 162 self::$path = dirname(FILE);
how about if dirname(FILE) change to user defined parameter?

if php_fast_cache.php in my folder directory like library/php_fast_cache.php
so it will create in library folder not in SRV_ROOT.CACHE; (user defined)

Thanks...

MySql queries

I couldn't cache mysql queries. Can you show an example pls?

[phpfastcache_v2.1_release] sqlite.php: unlink() permission denied

Apache 2.4 PHP 5.4 (Windows Server 2008 x86)

Warning: unlink(C:\...//sqlite/indexing): Permission denied in C:\...drivers\sqlite.php on line 328

I usually see that kind of error when there is a process not releasing the handle of those files.

Step to reproduce

<?php
require_once 'C:\xampp\htdocs\www.test.it\phpfastcache\trunk\phpfastcache_v2.1_release\phpfastcache\phpfastcache.php';

class MyCache extends phpFastCache
{
    private static $istance;
    Private $obCache;

    function __construct()
    {
                $option = array('securityKey' => 'aCache', 'path' => dirname(__FILE__));
        $this->obCache = parent::__construct('sqlite', $option);
    }

    public static function getIstance()
    {
        if( is_null(self::$istance) )
        {
            self::$istance = new self();
        }

        return self::$istance;
    }
}

if( $CacheData = MyCache::getIstance()->get('aKeyword') )
{
    die($CacheData);
}

MyCache::getIstance()->set('aKeyword','aValue', 60*60*24);

MyCache::getIstance()->clean();

echo 'No cache'; 
?>

ip.codehelper.io.php doesn't work

the website codehelper.io is not accessible since several days. Inside the files there is a relation with this website, the add on does'nt wok now.

mail

i see your are using a function to send bug errors via email. this section must be more configurable via public properties such as destination email, using SMTP (some hosting has blocked local smtp to prevent spam attack) i think you could integrate directly to php mailer line $mail = new PHPMailer();... and so on.. user must have phpMailer class in their server. and you should let user to set the path of php mailer class and "include_once" into the function (include files only if needed).

sorry for my bad english.

PDO CHMOD 0777

Hallo
I have a issued about pdo cache.

I created a modul for cron job, in cron job need to create a folder
cache/f011sdfasddsd8efed7as420323c793/ exampled. In these folder will be consist two files they are :
pdo.caching and config.41065cf4fd8asdf 7d52bedfda24a32adf75b1fe0.cache.ini

And I am considering for chmod it 0777 or Writable permission, I am afraid if some body can download these file via browser. I have test and it can be downloaded.

Other modul I set automatically, other module created cache APC, so I look cron job module and others moduls have created different cache, they are still in one application.

How to set chmod not to 0777 but still created pdo cache.

Thanks

regarding usage

hello,
i have downloaded phpfastcache from github..i am not getting the proper way to use it.
i have included
include("php_fast_cache.php");
phpFastCache::$storage = "auto";

i am not understanding few terms being used further like "product_page" and "identity_keyword"

Time Cache....

Hello Khoaofgod...

I want to ask about time of cache..

What do you mean 600 seconds = 5 minutes?

We know that 300 seconds = 5 minutes?

600 seconds = 10 minutes

I think it can make confuse in documentation and uses.

Maybe you have reasons, could you tell me?

Thanks...

Support for Redis?

Sorry if this is answered elsewhere, but I do not see any specific support planned for Redis. Do you plan to have support for it in the future?

X Cache is supported & Bugs Report here

X-Cache have supported.

phpFastCache::$storage = "xcache";

All bugs about x-cache please report here.

AUTO Mode Priority: APC, XCache, MemCached, MemCache, WinCache, PDO, Files

* phpFastCache::$useTmpCache = true; // default is FALSE
// faster checking cache for LOOP Only. If you don't use LOOP, don't spend more memory.
* Example:
* WHILE() {
*   $cache = phpFastCache::get("name");
* }
* LOOP() {
*   $cache = phpFastCache::get("name");
* }
*    --> THE NAME maybe duplicated some times, if you set $useTmpCache it will check from $Tmp first before IT connect to Cache Memory or Open Files to check.
*        Will be faster a little bit if you know what you are doing.

As another topic about auto clean up files cache.
The core right now added auto clean up files cache every 1 hour for "files" cache only.
You can do custom config by:

phpFastCache::$files_cleanup_after = 1; // hours(s)

Let me know if any bugs & issues OR This topic will be close at end of this month.

Fatal error: Call to a member function prepare()

HI,

I just downloaded the script and tested it, but i am getting this error when testing.php


Caching = auto
SET 1 -->
Fatal error: Call to a member function prepare() on a non-object in /public_html/phpfastcache/php_fast_cache.php on line 1665

I also get this error when trying the script with "auto" selected, works only when set o PDO.

Fatal error: Call to a member function prepare() on a non-object in /public_html/phpfastcache/php_fast_cache.php on line 1575

order for "auto"

Hi, i testing performace for cache aaand
first ist APC (best performace) +- 70ms
sqlite +- 320ms
files +- 70ms

then order is wrong... second sqlite si very slow

Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]

Dear Khoaofgod, suddenly in one of my projects, a fatal error displayed, and it cause some sections to be die.
This is the error message:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 5 database is locked' in /home/estqlal/public_html/includes/phpfastcache/drivers/sqlite.php:272 Stack trace: #0 /home/estqlal/public_html/includes/phpfastcache/drivers/sqlite.php(272): PDOStatement->execute(Array) #1 /home/estqlal/public_html/includes/phpfastcache/drivers/sqlite.php(244): phpfastcache_sqlite->deleteRow(Array) #2 /home/estqlal/public_html/includes/phpfastcache/phpfastcache.php(98): phpfastcache_sqlite->driver_get('SidebarArticles', Array) #3 /home/estqlal/public_html/sidebar.php(20): phpFastCache->get('SidebarArticles') #4 /home/estqlal/public_html/index.php(161): require_once('/home/estqlal/p...') #5 {main} thrown in /home/estqlal/public_html/includes/phpfastcache/drivers/sqlite.php on line 272

thanks for sharing

i want to write a simple file cache,find some ideals from your code,thanks

Fallback?

Does the fallback concept work? It doesn't for me. I just get an exception that says "Can't use this driver for your website!" when I try to use memcached with a fallback of files.

Here's my code.

$options = array(
    'fallback' => array(
        'memcached' => 'files'
    )
);
$cache = $cache = new phpFastCache('memcached', $options);

But looking through the phpfastcache code, I don't see any exception catching. Searching for the word fallback seems to result in almost nothing. It doesn't look like it could work.

how can i cache pdo query

how can i solve this code problem?

get("product_page"); if($products == null) { $products = $conn->prepare("SELECT text,time FROM small WHERE active='0' ORDER BY time DESC LIMIT 10"); $products->execute(); $cache->set("product_page",$products , 600); } while($obj = $products->fetch(PDO::FETCH_OBJ)){ ?>
text; ?>
time);} ?>

Composer issue

I'm trying to download the project with the use of the composer but I always get an error.

I'm using the command:
php composer.phar require "phpfastcache/phpfastcache":*

and I get:
Your requirements could not be resolved to an installable set of packages.

Problem 1
- The requested package phpfastcache/phpfastcache could not be found in any version, there may be a typo in the package name.

Potential causes:

Read http://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

Installation failed, reverting ./composer.json to its original content.

Is this method supported ?

REDIS

Do you plan to implement REDIS ? :) is faster than memcache and APC :)

End of support of APC for PHP 5.5.x and support of OPcache

Dear phpfastcache developers,

With the announcement of the end of support of APC within PHP 5.5.x and its replacement by OPcache, is there any plan to update the library to support OPcache ?

Thanks a lot and best regards,

Alexandre 8)

phpFastCache::$sys['method'] = "pdo";

I have a "Call to a member function prepare() on a non-object in /php_fast_cache.php on line 1536" Fatal error when trying to: $recentArticles = phpFastCache::get("recentArticles");

This problem disappears when I add a 'phpFastCache::$sys['method'] = "pdo";' line to the code. Why is it so?

XCache var cache was not initialized properly

Hallo Khoaofgod...

I using cronjob to run php script, but in log error i got this

[04-Jan-2014 12:09:01 Asia/Jakarta] PHP Warning: xcache_get() [function.xcache-get]: XCache var cache was not initialized properly. Check php log for actual reason in /home/xxx/public_html/new/libraries/php_fast_cache.php on line 1114

[04-Jan-2014 12:09:01 Asia/Jakarta] PHP Warning: xcache_set() [function.xcache-set]: XCache var cache was not initialized properly. Check php log for actual reason in /home/xxx/public_html/new/libraries/php_fast_cache.php on line 1105

How to fix it? I am using phpfastcache Revision 620

Manual cache file deletion?

I just started messing around with this. Works great so far. I was wondering if it's possible to manually delete cache files when you are using filesystem storage as the caching type? I don't see where the cache files are stored on the file system.

There are some cases where I need to manually delete the cache and let my webpage rebuild the cache because a DB query was modified and I can't wait until the cache expires. Is the only way to delete the cache to call $cache->delete()?

xcache_cleanup

For me xcache_cleanup gets this error:

Warning: xcache_clear_cache() expects exactly 2 parameters, 1 given in /PATH/TO/FILE/php_fast_cache.php

so i've modified the function like this:

private static function xcache_cleanup($option = array()) {
$cnt = xcache_count(XC_TYPE_VAR);
for ($i=0; $i < $cnt; $i++) {
xcache_clear_cache(XC_TYPE_VAR, $i);
}
return true;
}

and all works file when i call: phpFastCache::cleanup();

An error in 5.master.php - line 46

$cache2->setMulti(array("key1","value1", 300),
array("key2","value2", 600),
array("key3","value3", 1800),
);

Maybe the last comma is redundant?

Reference to $_SERVER on the command line

Hi,

Using the master phpfastcache_v2.1_release/phpfastcache/phpfastcache.php

I get a warning about $_SERVER['HTTP_HOST'] not existing when I use phpfastcache in a command-line php script which I have to fix with:

if (empty($_SERVER['HTTP_HOST'])) { // patch for phpfastcache referencing this
$_SERVER['HTTP_HOST'] = 'localhost';
}

Please could you remove such references or enable them to be set?

Private methods prevents inheritance

If I want to add some additional options for memcached, like compression it is hard to do because memcached_addserver method is private not protected.

Is it possible to add phpDoc compatibile syntax to each function (public are more important than the others).

Release 2.4.1

Release 2.4 will be release on next Monday Feb 02.

What's new

  • Redis supported
    "pecl install redis"
  • Cookie Driver
    Fun for who want to store cache on visitor's browser.
  • Non-Expring Cache for Object
    Example: set("keyword", $data); will be non-expire until you do delete("keyword");
  • Temporary Disabled phpFastCache
    use: phpFastCache::$disabled = true;
    After this line, all get("keyword") will return NULL;
  • Improved Files Cache for Busy Disk
    Busy Disk will skip caching object and continue without error_log problems.
  • Composers will be added
  • Improve fallback
    If specific driver that you set is not available then system will use "files" driver

Then March 03 will be release 2.5:
-- Planned for MongoDB
-- External Server Caching
-- and phpFastSQL.com will be release together.

Problems on increment, decrement & touch

I was adding a Redis driver when I spotted this:

$object being returned from

   function get($keyword, $option = array()) {
        if($this->is_driver == true) {
            $object = $this->driver_get($keyword,$option);
        } else {
            $object = $this->driver->driver_get($keyword,$option);
        }

        if($object == null) {
            return null;
        }
        return $object['value'];
    }

is not the entire array and only the 'value' so:

    function increment($keyword, $step = 1 , $option = array()) {
        $object = $this->get($keyword);
        if($object == null) {
            return false;
        } else {
            $value = (Int)$object['value'] + (Int)$step;
            $time = $object['expired_time'] - @date("U");
            $this->set($keyword,$value, $time, $option);
            return true;
        }
    }

    function decrement($keyword, $step = 1 , $option = array()) {
        $object = $this->get($keyword);
        if($object == null) {
            return false;
        } else {
            $value = (Int)$object['value'] - (Int)$step;
            $time = $object['expired_time'] - @date("U");
            $this->set($keyword,$value, $time, $option);
            return true;
        }
    }

    function touch($keyword, $time = 300, $option = array()) {
        $object = $this->get($keyword);
        if($object == null) {
            return false;
        } else {
            $value = $object['value'];
            $time = $object['expired_time'] - @date("U") + $time;
            $this->set($keyword, $value,$time, $option);
            return true;
        }
    }

will not work and will also mess up the cached values.

I'm fixing it by passing an option to the get method so it returns the entire array.

Will send a Pull request for both this issue and the Redis driver once resolved and tested.

Persistent cache

The file cache is deleted on server restart. I would like it to remain and honour the expiry I have set which in my case is 28 days.

Clear section of cache

I'd like to clear a section of my cache. Say for example that I store data by prefixing it with a namespace. Perhaps I cache some twitter data, facebook data, etc. I might store them as twitter.myvalue1, twitter.myvalue2, and facebook.myvalue1, facebook.myvalue2. How could I delete the cache entries for twitter? And I don't know all the names of the values. It's not necessary myvalue1/2/3/etc, I just know it starts with twitter.

Tags

Hello,
Introduction of tags will be?

skype me: khoaofgod

I will clean up the issues soon, because I am opening a forum to do support & continue develop other plugins for wordpress , carts , forum use phpFastCache.

This box gonna do issues only.

Skype me: If you have any problem or need fast support.
Skype: khoaofgod

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.