?
avatar Taste-IT
Taste-IT
14 Jul 2017

I have installed latest Version. I am coding an own component, which shows polls and uses jquery to load the result after voting.

If i select an answer of an poll and send this, i check rights and insert into database. After that jquery loads the result and shows it. Normaly i cant vote again and i got a message like this." You have voted before -> Show Results" - but with active Cache in Joomla in Browser Chrome, Firefox and IE11, i can reload the page and can vote again.

If i disable Cache Plugin and Cache in System Configuration, i have expected behavior and see mentioned message and cant vote again.

So i think its an Cache Problem in Joomla.

avatar Taste-IT Taste-IT - open - 14 Jul 2017
avatar joomla-cms-bot joomla-cms-bot - change - 14 Jul 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 14 Jul 2017
avatar mbabker
mbabker - comment - 14 Jul 2017

Page cache is working fine here. Remember the page cache is shared with all users, so you wouldn't want it to cache showing the "you've already voted" message. Since you say you're using jQuery to handle votes, I assume you have an AJAX request submitting the vote. In that request should be where you do your checks to determine if a user has voted. The core voting plugin works very similar to that, just using a normal form submission versus JavaScript.

avatar Taste-IT
Taste-IT - comment - 14 Jul 2017

I am not sure if you understand my problem. Thats the way it normaly works:

You call the Page in Joomla for the vote, the page is created / rendered via html and php with information from database and normaly shows you the vote. If you selcect your answer you can send this via the typical "vote" Button. This Button fire a jQuery Function which send Data over json to the php function which will do checks and normaly insert the answer into the Database. After that result will send back to this jQuery function which normaly remove the poll and shows the results. Thats ok and is working. If you now make a simple reload of the Page, the Vote is shown again, but if the Cache is disabled than the correct information like "you have still voted" is shown via php and some mysql Queries. At this point there is no jQuery involved. I assume Joomla holds some PHP Information in Cache or something like that.

avatar mbabker
mbabker - comment - 14 Jul 2017

The caching systems cache the result of rendering a section; with conservative cache enabled in the global config the resulting HTML of a component view, module layouts, etc. are what is cached, and page cache stores the rendered HTML page. So it's not re-executing any PHP logic when it uses the cached data, the design of the cache systems is that as little PHP logic is triggered as possible (since the steps that go into building a view typically include several database queries and plugin events).

So you couldn't efficiently cache your component layout area with a "if voted show this else show that" type logic, since the result could change depending on the user who triggers the request that re-caches that output and it would affect the output for all users after that. You would need to not cache your component's output (and inherently exclude the page(s) that voting system is enabled on from the page caching system) or include some JavaScript that decides which version of your voting area to show to users (fired on document ready) versus including that in the layout that gets generated and included in the cache.

avatar Taste-IT
Taste-IT - comment - 14 Jul 2017

Thanks. I am not knowingly cache something from this component. In jQuery function i have disabled cache. I am a bit confused since i check it in php if this user has voted the same question before and if i disable caching it works, but with cache this function seems not working and the vote is inserted again into database.
It seems that i do not fully understand the cache system. i cant understand why the cache system returns something, but the request from component php and database is something other ....

ok i can make an exclude of the menu entry, but that sound not ok. can i do something in coding to say "dont cache this"?
edit: i think i never had this before joomla version 3.7...
edit2: in view i use class JViewLegacy

avatar mbabker
mbabker - comment - 14 Jul 2017

In your controller's display method you can add logic to determine if the component section should be cached, that will take affect when the cache setting in the global config is enabled. Programatically, there isn't a way to hook into the page cache plugin, so you'll have to manually configure that.

I am a bit confused since i check it in php if this user has voted the same question before and if i disable caching it works, but with cache this function seems not working and the vote is inserted again into database.

Your function to check if the user has voted already won't run again if the component data has been cached. By default, the display task for components goes through https://github.com/joomla/joomla-cms/blob/3.7.3/libraries/legacy/controller/legacy.php#L631-L672 and that is the block that handles rendering the data from the cache or executing your component's code. In that block, when it makes the $cache->get() call, internally the cache handler checks to decide if there is a valid cache entry for that view and if so it is loaded from the cache and that's it; if the cache entry doesn't exist, or has expired, or you have caching disabled, then your view's display() method is executed. So your PHP logic won't run on every request if you have caching enabled, it will only run on requests where the system has to regenerate the cache because it doesn't exist or has expired (or if there is some error within the caching system we have a fallback here to just run your code to try and not display an error page just because the cache failed).

can i do something in coding to say "dont cache this"?

For your component, generally in your default controller you'll extend the display() method to add some extra logic (see https://github.com/joomla/joomla-cms/blob/3.7.3/components/com_content/controller.php#L57 for com_content as an example). Here you can set the $cachable parameter based on your own logic before calling the parent method. But again, that will only apply when dealing with the global config's cache option. When the page cache plugin is enabled, it works in a way that it caches the full page's HTML response and doesn't run probably 85-90% of the normal Joomla request cycle logic.

avatar Taste-IT
Taste-IT - comment - 14 Jul 2017

Hi,
i think there is an logical problem in the cache handler. Ok, first time the page is viewed and the poll is answered is ok. But if the page is reloaded, the php / mysql result says dont show the poll, instead show another html message, but it doesnt, because - as far i understand - the cache system says -> the view is cached and returns the view data for the answered poll - and thats because the php/mysql logic says - no! as far as there is no direct option for the view or component to deactivate the cache, its an problem with the cache logic. but as far as i understand, it doesnt happend if the view for answering the poll is send via form/post and a page reload is done. so i think its an problem with sending information via ajax...

avatar franz-wohlkoenig franz-wohlkoenig - change - 19 Jul 2017
Category com_cache
avatar franz-wohlkoenig franz-wohlkoenig - change - 19 Jul 2017
Status New Information Required
avatar brianteeman
brianteeman - comment - 20 Aug 2017

@mbabker from your writing this sounds like a problem in the users code not in the Joomla core. If so please close this issue

avatar mbabker mbabker - change - 20 Aug 2017
Status Information Required Closed
Closed_Date 0000-00-00 00:00:00 2017-08-20 15:31:07
Closed_By mbabker
avatar mbabker mbabker - close - 20 Aug 2017
avatar alor702000
alor702000 - comment - 13 Oct 2017

Re : Error of the file cache storage

go to configuration.php and put:
public $cache_handler = '';

Add a Comment

Login with GitHub to post a comment