cosenary / simple-php-cache Goto Github PK
View Code? Open in Web Editor NEWA light, simple but powerful PHP5 Cache Class which uses the filesystem for caching.
License: BSD 3-Clause "New" or "Revised" License
A light, simple but powerful PHP5 Cache Class which uses the filesystem for caching.
License: BSD 3-Clause "New" or "Revised" License
Can we have this available via Composer. It would help me better manage the packages.
Thanks.
I would like an example of using this class to cache my queries. My queries are returning objects, I see strings and arrays only in the examples.
I want to store data for a specific period but am not really sure the unit of time the store method expects
store($key, $data, <$expiration>);
Wondering if the expiration is in seconds, milliseconds. Not really sure
i Created a php file and run this code to grab a json and store in .cache file,
Everytime i refresh the php page, cache is also refreshed,
So Now shall I read the json data from the php file or from the .cache file to save api limits ?
Hi cosenary,
After using your lib for a while I realized that the function _checkExpired should be include in isCached function in order to check whether the cache is expired or not.
Am I right or wrong?
https://github.com/Wruczek/PHP-File-Cache
I loved Simple-PHP-Cache, its small and portable, fits everywhere and is very simple.
But the code is old, buggy and unmaintained.
I have released a full rewrite inspired by this library, called PHP-File-Cache.
It's similar to Simple-PHP-Cache, but also improved drastically.
refreshIfExpired
Hope it helps someone.
Tried creating a cache with 5 minutes expiration but it does not seems to update the new value after 5 minutes.
example:
$cache->setCache('title');
$cache->eraseExpired();
if ( $cache->isCached('main-header') ) {
print_r($cache->retrieve('main-header'))
} else {
$cache->store('main-header', "new header title", 360000);
}
Hi, I just came across this library today and I'm planning on implementing it on a project that I'm currently working on. The new project is essentially a new blogging app that retrieves and displays posts from the database, as you would expect. Problem is that it queries the database on every refresh even if there's no new data to be shown, which is why I want to go the caching route.
I've had a little play with this and I found that only the last data that's returned is cached, which is not what I want, so I literally have the last blog post displaying itself 6 times. I just want to ask: is there a way to cache data in a loop, properly?
{
"name": "cosenary/Simple-PHP-Cache",
"type": "library",
"require": {
"php": ">=5.2.0"
},
"autoload": {
"classmap": [
"."
]
}
}
There are more variables to add, but this is the basics :) I would like to implement this with composer.
I Put cache class into foreach loops but cache class only add/set one data into cache file.
code:
foreach($_POST['audio'] as $audio){
SQL::put("INSERT INTO " . NEWS_FILES . " (news_id, url, type) VALUES (?, ?, ?)", $id, $audio,"audio");
$c->store($id, array(
'action' => array(
$id, $video,"audio")
));
}
cache File:
{"202":{"time":1410452801,"expire":0,"data":{"action":[202,"http://localhost/user/uploads/files/1/thumbs/1/audio/download-kid-photo-c.jpg","audio"]}}}
I have 4 files for id 202 But cache class insert only one files in file. how to fix this?
Thanks for this wonderful and simple caching library. It's exactly what I need!
Just FYI, this notice occurs on line 105 of cache.class.php in my version
of PHP, 5.6.14.
The fix is to only serialize when $type == 'data'. My quick fix was this:
/**
* Retrieve cached data by its key
*
* @param string $key
* @param boolean [optional] $timestamp
* @return string
*/
public function retrieve($key, $timestamp = false) {
$cachedData = $this->_loadCache();
(false === $timestamp) ? $type = 'data' : $type = 'time';
if (!isset($cachedData[$key][$type])) return null;
if ($type == 'time') {
return $cachedData[$key][$type];
}
return unserialize($cachedData[$key][$type]);
}
When I call store(), only the first value is stored. It happens in a AWS instance, but not in my XAMPP.
I can clear the cache and write again a different data, but only the first one.
Any Idea?
Is it measured in seconds, milliseconds, minutes, hours? If I set $c->store('text', 'Hello', 5000) will that cache be stored for 5 seconds before expiring? After it expires, does it get deleted?
Hey hi,
simple cache 2 is comming or gived up?
thanx
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.