afshin.m Posted May 28, 2010 Share Posted May 28, 2010 Hello, I'm programming an advanced caching system that work with PHP but i have an small problem. I want to know when the pages content changed to remove the page cache from cache folder and make a new cache file with new content. i don't want to work with cache time... Please help me, thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/203170-making-an-advanced-cache-system/ Share on other sites More sharing options...
Zyx Posted May 28, 2010 Share Posted May 28, 2010 If you do not want to work with time, how do you want to implement that? Asking "when" means using some form of storing information about time. The only other alternative is a tag/category system - you tag the cached content and update the cache explicitely while adding something, requesting i.e. to remove the cache entries with the specified tag. Quote Link to comment https://forums.phpfreaks.com/topic/203170-making-an-advanced-cache-system/#findComment-1064500 Share on other sites More sharing options...
afshin.m Posted May 28, 2010 Author Share Posted May 28, 2010 If you do not want to work with time, how do you want to implement that? Asking "when" means using some form of storing information about time. The only other alternative is a tag/category system - you tag the cached content and update the cache explicitely while adding something, requesting i.e. to remove the cache entries with the specified tag. Thank you dear Zyx, Many caching systems work with time, it means renew the cache file every 5min etc. But i don't want to do that, i want to renew the cache file only WHEN the page content changed... Thank you again Quote Link to comment https://forums.phpfreaks.com/topic/203170-making-an-advanced-cache-system/#findComment-1064516 Share on other sites More sharing options...
pornophobic Posted May 28, 2010 Share Posted May 28, 2010 I'm not sure what kind of caching you're doing as I've seen a few different types. One is where it pulls page data out of a database and creates a file. I think this is what you're doing. You could always md5_file() or create an md5 checksum of the page data and have that stored somewhere. It could check the md5 sum of the data and if it's not the same, it recaches the page. Quote Link to comment https://forums.phpfreaks.com/topic/203170-making-an-advanced-cache-system/#findComment-1064597 Share on other sites More sharing options...
ignace Posted May 28, 2010 Share Posted May 28, 2010 If you want to create a new cache upon change, then create the new cache when the page content changes. By this I mean when the user edits a page create the new cache when he submits it. Quote Link to comment https://forums.phpfreaks.com/topic/203170-making-an-advanced-cache-system/#findComment-1064598 Share on other sites More sharing options...
travo1992 Posted May 29, 2010 Share Posted May 29, 2010 Why not just use the database? The cache you are proposing is replicating the functionality ayway, the only difference is that eg. MySQL is optimised to handle data, where as PHP isnt optimised for file handling. Quote Link to comment https://forums.phpfreaks.com/topic/203170-making-an-advanced-cache-system/#findComment-1064932 Share on other sites More sharing options...
trq Posted May 29, 2010 Share Posted May 29, 2010 Why not just use the database? The cache you are proposing is replicating the functionality ayway, the only difference is that eg. MySQL is optimised to handle data, where as PHP isnt optimised for file handling. Responding to a request with a static file is almost always more efficient than re-generating a new page dynamically upon each request. Quote Link to comment https://forums.phpfreaks.com/topic/203170-making-an-advanced-cache-system/#findComment-1064933 Share on other sites More sharing options...
travo1992 Posted May 29, 2010 Share Posted May 29, 2010 LOL Just it just occurred to me as I was about to reply that not needing time removes the time checking functions But the system the OP talks about it is not really a cache, its more of a flat file db Quote Link to comment https://forums.phpfreaks.com/topic/203170-making-an-advanced-cache-system/#findComment-1064958 Share on other sites More sharing options...
trq Posted May 29, 2010 Share Posted May 29, 2010 LOL Just it just occurred to me as I was about to reply that not needing time removes the time checking functions But the system the OP talks about it is not really a cache, its more of a flat file db It sounds like a cache to me. It just seems the OP wants the cache flushed when the relevant data is changed. Quote Link to comment https://forums.phpfreaks.com/topic/203170-making-an-advanced-cache-system/#findComment-1064963 Share on other sites More sharing options...
afshin.m Posted May 29, 2010 Author Share Posted May 29, 2010 All friends, thanks for your responds. Based on my research about caching systems, it's not possible to re-generate cache file only when the file changed, you should use a period (for example 5min) to re-generate cache file or remove all caches and make a new cache file. This is true? Quote Link to comment https://forums.phpfreaks.com/topic/203170-making-an-advanced-cache-system/#findComment-1064978 Share on other sites More sharing options...
travo1992 Posted May 29, 2010 Share Posted May 29, 2010 Unless you are making a game or an app with alot of data changes that needs to be fairly up to date, I wouldnt use 5 mins. The cache on my cms site (wip) has a cache time of a week I think. Quote Link to comment https://forums.phpfreaks.com/topic/203170-making-an-advanced-cache-system/#findComment-1064980 Share on other sites More sharing options...
pornophobic Posted June 2, 2010 Share Posted June 2, 2010 OP another way(s) that you could do this, if you haven't figure it out already, well I can list a few ways this could be done. 1) You can store an md5sum of all the data on the page in a database or file and check those on each page load. 2) If your pages are user generated pages from your own site, have the page update on the user saving the page. Otherwise (similar to what I mentioned with the HTTP headers) 3) Use HTTP headers. (304 = not changed) and Etags. That's all I can think of at the moment. here are some links: http://en.wikipedia.org/wiki/HTTP_ETag http://en.wikipedia.org/wiki/List_of_HTTP_headers http://php.net/manual/en/function.header.php http://php.net/manual/en/function.md5.php http://www.php.net/manual/en/function.md5-file.php These two aren't necesarrily mentioned, but an alternative hashing construct in php, http://www.php.net/manual/en/function.sha1-file.php http://www.php.net/manual/en/function.sha1.php And for the sake of 'you might find something else useful in this list' http://www.php.net/manual/en/ref.strings.php Quote Link to comment https://forums.phpfreaks.com/topic/203170-making-an-advanced-cache-system/#findComment-1066749 Share on other sites More sharing options...
afshin.m Posted June 2, 2010 Author Share Posted June 2, 2010 OP another way(s) that you could do this, if you haven't figure it out already, well I can list a few ways this could be done. 1) You can store an md5sum of all the data on the page in a database or file and check those on each page load. 2) If your pages are user generated pages from your own site, have the page update on the user saving the page. Otherwise (similar to what I mentioned with the HTTP headers) 3) Use HTTP headers. (304 = not changed) and Etags. That's all I can think of at the moment. here are some links: http://en.wikipedia.org/wiki/HTTP_ETag http://en.wikipedia.org/wiki/List_of_HTTP_headers http://php.net/manual/en/function.header.php http://php.net/manual/en/function.md5.php http://www.php.net/manual/en/function.md5-file.php These two aren't necesarrily mentioned, but an alternative hashing construct in php, http://www.php.net/manual/en/function.sha1-file.php http://www.php.net/manual/en/function.sha1.php And for the sake of 'you might find something else useful in this list' http://www.php.net/manual/en/ref.strings.php Thanks for your useful response but i can you please explain HTTP_ETag and give some examples? And about (304 = not changed), this is only relevant to client and browser cache as far as i know, right? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/203170-making-an-advanced-cache-system/#findComment-1066856 Share on other sites More sharing options...
ignace Posted June 3, 2010 Share Posted June 3, 2010 And about (304 = not changed), this is only relevant to client and browser cache as far as i know, right? Indeed this puts the cache on the client instead on the server. So, when a client asks for a particular page which has not been changed since his lasts visit you return a "304 Not Modified" header and the browser will use the cached page. Quote Link to comment https://forums.phpfreaks.com/topic/203170-making-an-advanced-cache-system/#findComment-1067104 Share on other sites More sharing options...
afshin.m Posted June 3, 2010 Author Share Posted June 3, 2010 so useful...i don't use this parameter in my caching system so when i refresh the page, nothing loaded from cache And just another question, is there any limitation for browser caching? Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/203170-making-an-advanced-cache-system/#findComment-1067136 Share on other sites More sharing options...
ignace Posted June 3, 2010 Share Posted June 3, 2010 so useful...i don't use this parameter in my caching system so when i refresh the page, nothing loaded from cache And just another question, is there any limitation for browser caching? Thank you! Yes, users can turn it off. In which they will always retrieve the page. Quote Link to comment https://forums.phpfreaks.com/topic/203170-making-an-advanced-cache-system/#findComment-1067226 Share on other sites More sharing options...
afshin.m Posted June 3, 2010 Author Share Posted June 3, 2010 Thanks, good Now i check a website with my caching system and also enable YSlow... I get this errors: Grade F on Add Expires headers There are 93 static components without a far-future expiration date. * (no expires) http://localhost/cache/test_files/mod_thumbsup.css ... I think this is because i redirect all images/js/css with .htaccess to another address like this : css_minify.php?css=[cssaddress] image_compress.php?image=[imageaddress] js_packer.php?js=[jsaddress] And also i don't set any expires header in my PHP files (in js_packer.php for example) How can i set any expires header in my PHP files? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/203170-making-an-advanced-cache-system/#findComment-1067291 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.