In one of my site I am using voting api and five star module.

When anonymous user rate the product then vote is increased by one and
then if we refresh the page old vote count is displayed
if we refresh the page by putting ?fsdfsd after the url then correct vote count will display.

I added
hook_votingapi_results($cached, $entity_type, $entity_id) {
// Get the Entity URI
$uri = entity_uri($entity_type, node_load($entity_id));
// Turn it into a URL.
$path = url($uri['path'], array('absolute' => TRUE));
// Use a wildcard to catch paths with query strings.
cache_clear_all($path, 'cache_page', TRUE);
cache_clear_all("field:$entitytype:$entityid", 'cache_field');
cache_clear_all("field:node:$nid", 'cache_field');
// cache_clear_all('content:' . $node->nid, 'cache_content', TRUE);
}

and it is page caching issue for anonymous users only.

So I dont want to use ?fsdfsd after the url to clear cache.

Comments

parul99 created an issue. See original summary.

parul99’s picture

Title: Need to clear cache manually after rating » Correct voting results count are visible after clearing cache
Priority: Critical » Major
pifagor’s picture

Status: Active » Postponed (maintainer needs more info)

Dear @parul99
You may have a problem similar to - https://www.drupal.org/project/fivestar/issues/2498161

parul99’s picture

Dear @pifagor,

No my issue is not similar to this.

Please find details of my issue
Anonymous user can vote then we can see the voting count.
But after page reload it is showing old count.
and if we manually clear cache(by adding query string after url e.g http:abc.com/xyz/?fhjskhfaksf) then it shows updated voting count.

pifagor’s picture

Dear @parul99
Do you use fivestar?
I meant - https://www.drupal.org/project/fivestar/issues/2297231

parul99’s picture

Dear @pifagor,

Yes.

avpaderno’s picture

Assigned: parul99 » Unassigned
Priority: Major » Normal
Issue tags: -voting api, -anonymous users, -caching
pifagor’s picture

Status: Postponed (maintainer needs more info) » Fixed
pifagor’s picture

Status: Fixed » Closed (fixed)
yogeyoge’s picture

Hi,

I am sharing a quick fix which worked for me.

Findings:
Once a page is cached the Voting API response is also cached so the updated count values will not be displayed after page refresh.
Where as after clearing cache the updated count will be visible.

Solution
On click of the like button store the updated value in cookie using jquery. After page refresh read the cookie count value and update the data.