Correct voting results count are visible after clearing cache

Created on 28 January 2020, almost 5 years ago
Updated 27 June 2024, 6 months ago

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.

💬 Support request
Status

Fixed

Version

2.15

Component

Code

Created by

🇮🇳India parul99

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India YogeYoge

    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.

Production build 0.71.5 2024