Page caching mod for sNews 1.7
Hi again, as promised, I have completed my caching mod for sNews 1.7, and here is my initial release.
What the hell is caching and do I need it?
Well, basically what we're doing with this mod is saving a page's output into a raw HTML document, and we serve that page until there's a change that would require hitting the database again. If your site is like mine and gets a few comments a day and you're adding a few articles a day, then yes, this mod would likely help you considerably.
Uh, what? I need an example please.
Fair enough, say you have an article with 20 comments, every time someone visits that page, you're querying the database for the article, all the comments, as well as anything else on the page (site title, description, categories list, pages, recent comments list, recent articles, my related posts mod, etc). With this mod the first time someone calls the page all information would be pulled from the database and the resulting HTML will be saved into your "cache" folder, and then subsequently served to users after that, up until a new comment is posted, an article is added/edit/deleted, etc.
Sound good? Great, this is another super easy mod to implement, first download the package and unzip.
VERSION history
[1.0.3] - added code to strip failed comments
[1.0.2] - fixed the check for approved comments, should properly empty the cache now
[1.0.1] - added "remember me" function for my sticky forms mod
[1.0.0] - initial release
Now modify the following variables inside the mod.cache.php file. They are self-explanatory, and the comments inside the file should assist you.
$cache_dir = '/home/mysite/cache'; $cache_keep_days = '7'; $cache_polls = '0';
Cool, now upload mod.cache.php to the same directory as your snews.php and index.php files. Create the "cache" directory you specified now as well, if you haven't already.
Now open your index.php file add add the following at the top, just below your snews.php include (and poll include if you have it), like the following;
<?php
include('snews.php');
include('mod.cache.php');
//include("mod_poll/poll_functions.php"); //uncomment if you're using my polls mod
startCache();
?>
Now add this to the very bottom of your index.php file;
<?php outputCache(); ?>
Yeah, that's it, upload index.php and browse your site when you're not logged in, you'll see your cache directory start filling up and notice your MySQL database getting only one query per page once cached. Edit an article or post a comment and watch the cache folder empty.



Comments
RSS Comments Feed
Matt
Yes, you need to create a directory on your server and point the script to it, i.e. create the cache directory in the same as snews.php, it'll look something like this;
then set it up in the script;
Once you've set up caching properly, you should see the cache folder start filling up with files as people view new pages, and it should empty whenever you edit a page, post a comment, etc.
To verify SQL queries you can monitor your server, but if you don't have the ability, I will see if I can write up a quick and easy way to display the query count directly from the script and post it back here later.
BS0D
Thanks again for the help, and for your awesome work... now I've got a fully optimized and customized CMS :)
BS0D
Does it affect google ranking or SEO in any way?
It seems like google has indexed the categories on my website, but not the articles themselves :(
Matt
No, caching wouldn't have any affect on SEO, it's just serving a saved copy of the HTML.
What makes you think Google isn't indexing the articles? Are you using Google's Webmaster Tools?
Does it match using https://www.google.com/advanced_search when searching just your domain without any keywords?
BS0D
Well I know a bunch of google search methods, like "site:mydomain.com" which shows you all the indexed pages for your domain, and only the categories show up there.
I also tried "site: mydomain filetype:pdf intitle:mypdftitle" and other things like that and nothing shows up but the categories, none of the document that i link to in my articles show up.
For some reason I have to manually submit every single article cause google doesn't seem to see them. I do have a meta "index, follow" though.
it's sort of confusing.
Matt
What you really need is an XML sitemap, and then add that sitemap to your site in Google Webmaster Tools.
I had hacked together a sitemap generator for sNews, I'll add that to my list of sNews things to publish. Check back here in a few days, I'll see if I can clean that up and make it public.
BS0D
I already have a xml sitemap. I've been a webmaster for years so I know all these tricks and I use google analytics & webmasters ;)
I'm just a bit dumb when it comes to PHP so I thought maybe it was something I modified in the code that messed up the indexing ^^
Again, thanks for all your work, and most of all for sharing it. There are very few resources for snews out there and you seem to be the only one who loves it as much as I do for its simplicity and functionality!
Matt
I just threw my sitemap add-on up anyways, I should've released it ages ago, it's so simple.