Cache and article hits issue
Moderator: General Support Moderators
Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
-
- Joomla! Intern
- Posts: 64
- Joined: Sun May 02, 2010 9:50 pm
Cache and article hits issue
Hello!
When i set cache option ON, on my joomla site, the article HITS stop counting at all.
How can i use cache properly but not affecting the counting function?
Thanks!
When i set cache option ON, on my joomla site, the article HITS stop counting at all.
How can i use cache properly but not affecting the counting function?
Thanks!
-
- Joomla! Apprentice
- Posts: 45
- Joined: Mon Mar 30, 2009 9:43 pm
- Contact:
Re: Cache and article hits issue
Counting function is bad and doesn't give you proper information.
Use Google Analytic. It is about 98% right.
Use Google Analytic. It is about 98% right.
-
- Joomla! Intern
- Posts: 64
- Joined: Sun May 02, 2010 9:50 pm
Re: Cache and article hits issue
That's kind of bad solution for this
Thanks anyway, i will wait for actual solution.

Thanks anyway, i will wait for actual solution.
- kenmcd
- Joomla! Champion
- Posts: 5672
- Joined: Thu Aug 18, 2005 2:09 am
- Location: California
- Contact:
Re: Cache and article hits issue
EDITEDvbarlakoski wrote:When i set cache option ON, on my joomla site, the article HITS stop counting at all.
How can i use cache properly but not affecting the counting function?
The full page cache affects anything which has regular updates.
Which is why the full page cache can often have limited usefulness.
.
Last edited by kenmcd on Fri Nov 23, 2012 6:29 pm, edited 1 time in total.
██ LibreTraining
-
- Joomla! Intern
- Posts: 64
- Joined: Sun May 02, 2010 9:50 pm
Re: Cache and article hits issue
So, Conservative cache caches just display or full page cache, because when cache expires, hits are not updated at all!
- kenmcd
- Joomla! Champion
- Posts: 5672
- Joined: Thu Aug 18, 2005 2:09 am
- Location: California
- Contact:
Re: Cache and article hits issue
.
What I previously posted above was incorrect (so I edited it).
Hits are not counted in the background when the full page is cached.
Joomla counts hits when the page is built, and since it is not being built, no counting.
The best solution is to use external analytics as suggested above.
.
What I previously posted above was incorrect (so I edited it).
Hits are not counted in the background when the full page is cached.
Joomla counts hits when the page is built, and since it is not being built, no counting.
The best solution is to use external analytics as suggested above.
.
██ LibreTraining
-
- Joomla! Intern
- Posts: 64
- Joined: Sun May 02, 2010 9:50 pm
Re: Cache and article hits issue
I have found third-party plugin CacheControl, and i forbid option=com_content&view=article to cache, so, i have my hits back.
Joomla developers should really look into this thing.
Thanks for help!
Joomla developers should really look into this thing.
Thanks for help!
- kenmcd
- Joomla! Champion
- Posts: 5672
- Joined: Thu Aug 18, 2005 2:09 am
- Location: California
- Contact:
Re: Cache and article hits issue
.
Then you have basically disabled caching for all content.
That makes no sense to me.
Just turn the cache plug-in Off instead.
.
Then you have basically disabled caching for all content.
That makes no sense to me.
Just turn the cache plug-in Off instead.
.
██ LibreTraining
-
- Joomla! Intern
- Posts: 64
- Joined: Sun May 02, 2010 9:50 pm
Re: Cache and article hits issue
Its off for Article View from com_content, not for blog view, not for featured view, not for modules outside that view, not for other components. How this does not make sense?
-
- Joomla! Apprentice
- Posts: 11
- Joined: Sun Jun 22, 2008 8:28 pm
Re: Cache and article hits issue
same problem
system: Joomla 2.5.8
if cache enabled article hits stopping.
(
system: Joomla 2.5.8
if cache enabled article hits stopping.

-
- Joomla! Guru
- Posts: 530
- Joined: Tue Nov 29, 2011 2:43 pm
- Location: Bournemouth
- Contact:
Re: Cache and article hits issue
To be honest, the hits counter within Joomla is pretty naff. Most opt to use external applications to monitor success of pages in a much detailed way than just 1 hit, 2 hits, and so on.
-
- Joomla! Intern
- Posts: 64
- Joined: Sun May 02, 2010 9:50 pm
Re: Cache and article hits issue
Is there any way in template_name/html/com_content/article/default.php to make connection with the database and increase the hits count? In that way, that query wont be cached i think or i'm wrong?
It seems wrong that cache stops hits counting, because there is ordering by hits option.
It seems wrong that cache stops hits counting, because there is ordering by hits option.
- bradm
- Joomla! Explorer
- Posts: 369
- Joined: Tue Apr 19, 2011 1:58 pm
- Location: Virginia Beach, Va
- Contact:
Re: Cache and article hits issue
I know this is an older post, but I was able to come up with a solution for my website, increasing hits even if a cached page is being served. I posted the basic concept of the solution here: http://joomlacode.org/gf/project/joomla ... m_id=29831
It does involve a change to the core, but it works, and that's what I needed. If anyone has any questions as to how to get this working, just let me know.
It does involve a change to the core, but it works, and that's what I needed. If anyone has any questions as to how to get this working, just let me know.
Please let me know if I can help any further.
Thanks, BradM, with http://www.inmotionhosting.com Support
Thanks, BradM, with http://www.inmotionhosting.com Support
-
- Joomla! Virtuoso
- Posts: 4025
- Joined: Mon Nov 25, 2013 4:35 pm
- Location: Montreal, Canada
- Contact:
Re: Cache and article hits issue
Another way that doesn't involve modifying the core, is to create a system plugin that is run after the cache plugin runs, and that system plugin will update the page count. This'll work and it doesn't involve changing the core.
http://www.itoctopus.com - Joomla consulting at its finest
https://twitter.com/itoctopus - Follow us on Twitter
https://twitter.com/itoctopus - Follow us on Twitter
-
- Joomla! Intern
- Posts: 64
- Joined: Sun May 02, 2010 9:50 pm
Re: Cache and article hits issue
There is a hack that works with Conservative and Progressive cache but not with System Cache.
In Site ROOT/index.php after $app->route(); insert this code:
This will update hits in database in real time, but in article view will update every time when cache session expires with actual database hits.
In Site ROOT/index.php after $app->route(); insert this code:
Code: Select all
if (isset($_GET['view']) && strtolower($_GET['view']) == 'article') {
$articleId = (int) $_GET['id'];
$db = JFactory::getDBO();
$db->setQuery(
'UPDATE #__content' .
' SET hits = hits + 1' .
' WHERE id = '.(int) $articleId
);
$db->query();
}
- bradm
- Joomla! Explorer
- Posts: 369
- Joined: Tue Apr 19, 2011 1:58 pm
- Location: Virginia Beach, Va
- Contact:
Re: Cache and article hits issue
Hi @itoctopus and @vbarlakoski,
Great ideas! Were you able to prevent Joomla from updating the hits two times in the event someone was not seeing a cached version of the page? IE, the code / plugins you described would update the hits, and then the normal Joomla code would run and update the hit again.
Great ideas! Were you able to prevent Joomla from updating the hits two times in the event someone was not seeing a cached version of the page? IE, the code / plugins you described would update the hits, and then the normal Joomla code would run and update the hit again.
Please let me know if I can help any further.
Thanks, BradM, with http://www.inmotionhosting.com Support
Thanks, BradM, with http://www.inmotionhosting.com Support
-
- Joomla! Intern
- Posts: 64
- Joined: Sun May 02, 2010 9:50 pm
Re: Cache and article hits issue
Joomla code will run once to activate new cache. So it will update hit once. I think its better to have one time double hit every time cache expires, than have no hits at all while cache is active.
But, this is temporary fix, it should not be permanent one if you need to edit the core.
I hope that Joomla will adapt the system to work properly with or without cache. Hits must be excluded from caching.
But, this is temporary fix, it should not be permanent one if you need to edit the core.
I hope that Joomla will adapt the system to work properly with or without cache. Hits must be excluded from caching.
-
- Joomla! Apprentice
- Posts: 30
- Joined: Fri Feb 14, 2014 8:59 am
Re: Cache and article hits issue
HI
everyone
i tried the solution by @vbarlakoski
but the problem is still there ,
As i tested it for joomla 3.2.2 the article hit counter call is different in both cases(joomla3.2.2 and joomla2.5.x)
in joomla 3.2.2 the article hit counter is increased by
this code
I tried it to add in the root/index.php file but its not working for me , may be the issue is incorrect implementation of the above code .
is there anyone who will help me to solve this known joomla bug?
Regards
everyone
i tried the solution by @vbarlakoski
but the problem is still there ,
As i tested it for joomla 3.2.2 the article hit counter call is different in both cases(joomla3.2.2 and joomla2.5.x)
in joomla 3.2.2 the article hit counter is increased by
Code: Select all
public function hit($pk = 0)
{
$input = JFactory::getApplication()->input;
$hitcount = $input->getInt('hitcount', 1);
if ($hitcount)
{
$pk = (!empty($pk)) ? $pk : (int) $this->getState('article.id');
$db = $this->getDbo();
$db->setQuery(
'UPDATE #__content' .
' SET hits = hits + 1' .
' WHERE id = ' . (int) $pk
);
try
{
$db->execute();
}
catch (RuntimeException $e)
{
$this->setError($e->getMessage());
return false;
}
}
return true;
}
this code
I tried it to add in the root/index.php file but its not working for me , may be the issue is incorrect implementation of the above code .
is there anyone who will help me to solve this known joomla bug?
Regards
-
- Joomla! Intern
- Posts: 64
- Joined: Sun May 02, 2010 9:50 pm
Re: Cache and article hits issue
I have done it this way:
I`m using jotCache for page caching.
Then i have created module that runs code for article hits increase.
Then I have excluded the module from JotCache caching.
This works perfectly in 2.5.
I`m using jotCache for page caching.
Then i have created module that runs code for article hits increase.
Code: Select all
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
if (isset($_GET['view']) && strtolower($_GET['view']) == 'article') {
$articleId = (int) $_GET['id'];
$db = JFactory::getDBO();
$db->setQuery(
'UPDATE #__content' .
' SET hits = hits + 1' .
' WHERE id = '.(int) $articleId
);
$db->query();
}
?>
This works perfectly in 2.5.
-
- Joomla! Apprentice
- Posts: 30
- Joined: Fri Feb 14, 2014 8:59 am
Re: Cache and article hits issue
HI @vbarlakoski
is it custom html module ??
any idea for joomla3.2.2?
is it custom html module ??
any idea for joomla3.2.2?
-
- Joomla! Intern
- Posts: 64
- Joined: Sun May 02, 2010 9:50 pm
Re: Cache and article hits issue
You should try it.. Its custom module, that is changing the db values, so it should work in 3 too. Please share the result if you try it.
-
- Joomla! Fledgling
- Posts: 1
- Joined: Thu Nov 20, 2008 12:49 pm
Re: Cache and article hits issue
Does it also work with K2 Items?
-
- Joomla! Apprentice
- Posts: 30
- Joined: Fri Feb 14, 2014 8:59 am
Re: Cache and article hits issue
Hi the issue is solved .
-
- Joomla! Apprentice
- Posts: 36
- Joined: Mon Aug 24, 2015 5:20 pm
Re: Cache and article hits issue
All of you be aware that this is SQJ Injection and this brings certain security risks. Did you ever heard about sanitizing inputs?vbarlakoski wrote: ' WHERE id = '.(int) $articleId
- changlee
- Joomla! Explorer
- Posts: 465
- Joined: Tue Nov 20, 2007 11:05 am
- Location: Greece
- Contact:
Re: Cache and article hits issue
Hello! Have you tried that option for Joomla 3.x also?vbarlakoski wrote:I have found third-party plugin CacheControl, and i forbid option=com_content&view=article to cache, so, i have my hits back...
If you do not programm your life, someone else will do it for you.
SMTP Newsletter APP: https://www.emailbat.com
SMTP Newsletter APP: https://www.emailbat.com
-
- Joomla! Apprentice
- Posts: 6
- Joined: Fri Nov 30, 2012 10:56 am
Re: Cache and article hits issue
I made simple system plugin based on Your solution. I think plugin should fit better then module. Just install and enable it ("sittelicznik") in plugins.
Tested on Joomla 3.6.5 but it is so simple that it shuold work on all verssions.
Remember - if You disable cache then hits will by doubled every refresh. If You have cache enabled then hits will be doubled only from time to time so it's not precize solution.
Tested on Joomla 3.6.5 but it is so simple that it shuold work on all verssions.
Remember - if You disable cache then hits will by doubled every refresh. If You have cache enabled then hits will be doubled only from time to time so it's not precize solution.
You do not have the required permissions to view the files attached to this post.
-
- Joomla! Fledgling
- Posts: 1
- Joined: Tue Jun 20, 2017 9:15 pm
Re: Cache and article hits issue
not work on 2.7.2 

- pe7er
- Joomla! Master
- Posts: 24215
- Joined: Thu Aug 18, 2005 8:55 pm
- Location: Nijmegen, Netherlands
- Contact:
Re: Cache and article hits issue
Actually, to have it working on Joomla 3 you should change the XML filealfa6 wrote:I made simple system plugin based on Your solution. I think plugin should fit better then module. Just install and enable it ("sittelicznik") in plugins.
Tested on Joomla 3.6.5 but it is so simple that it shuold work on all verssions.
Code: Select all
<extension version="2.5" type="plugin" group="system">
Code: Select all
<extension version="3.0" type="plugin" group="system">
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com
Peter Martin, Global Moderator
Company website: https://db8.nl - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com