Welcome Guest, Not a member yet? Register   Sign In
Readers counting does not work when caching
#1

[eluser]Unknown[/eluser]
Hello,

I have a content management system built with CoideIgniter. I used it to publish articles.

I count number of readers for each article. Everytime the page of an article is displayed, the article is loaded from mysql database to a view and there's an insert query to log IP address of reader and an article ID as a new row in database.

But when I enable caching it just shows the cached view, but new row insert does not work.

Any ideas how to insert a row before loading a cached view?

Insert code in controller:
Code:
$data = array(
   'article_id' => strip_tags($id) ,
   'ip' => $this->input->ip_address()
);

$this->db->insert('articles_impressions', $data);

And a cache code (caching for five minutes):
Code:
$this->output->cache(5);
#2

[eluser]jim-_-[/eluser]
I'm not sure if this is the same issue, but I use Varnish as caching. (a system that caches before Apache is called) for everything to work properly I needed to do few work around to get the actual IP of the user viewing my page to get to Apache(webserver) otherwise everyone looked like they had the 127.0.0.1 IP so if this was the issue your counter would think everyone where the same person..

I'm not sure this is your issue, but if you try printing out the IP of the viewer on a site you are caching you would see if it was similar.
#3

[eluser]Aken[/eluser]
When using the Output class' caching feature, if a valid cache file is found for a particular page, the entire controller instantiation process is skipped, and the Output class takes care of loading the cached file.

You might need to use the Cache drivers instead, in which case the cache for that particular page would be controlled via the controller, not the Output class. Then you can add any DB changes and such around the page request as needed.
#4

[eluser]Unknown[/eluser]
[quote author="Aken" date="1349239549"]When using the Output class' caching feature, if a valid cache file is found for a particular page, the entire controller instantiation process is skipped, and the Output class takes care of loading the cached file.

You might need to use the Cache drivers instead, in which case the cache for that particular page would be controlled via the controller, not the Output class. Then you can add any DB changes and such around the page request as needed.[/quote]

thanks. do you recommend some of the drivers?
#5

[eluser]Aken[/eluser]
I don't have much experience with any drivers except the File one (which is just a file-based cache, really simple). I'd say look into both APC and Memcached and see which one seems a better fit for you. Maybe your hosting environment has one installed already - that'd obviously be an easy choice then.




Theme © iAndrew 2016 - Forum software by © MyBB