1

I have an issue with caching ajax calls, I am using ajax calls to count my post views and because of my high traffic I am not able to hit the database directly, so I want to store post views in cache and then save them in database on minutely intervals. The problem is wp_cache_add() is overridden by Litespeed Cache plugin and in this plugin's function there is a function call before storing cache data which checks for defined('WP_ADMIN') which is always true in admin-ajax. So how can I bypass this without enabling admin cache in this plugin settings?

  • 1
    Have you tried to turn on `Settings > Advance > Object Cache > Cache Wp-Admin`? It will allow you to use wp_cache_add on `defined('WP_ADMIN')`. But in fact, this is a bug, you can follow this post: https://wordpress.org/support/topic/solution-for-image-optm-hash-does-not-match-error/ to remove the `_can_cache` condition. – Stanley Cheung Jan 14 '20 at 18:02
  • Turning on that option will cache wp-admin area which I don't want to do, I only want to cache that specific ajax call – Ali Mohammadi Jan 21 '20 at 13:39
  • 1
    Then you need to remove rows 453 – 455 in plugin/litespeed-cache/inc/object.class.php: `if ( ! $this->_can_cache() ) { return null ; }` this bug will be fixed after v3.0 – Stanley Cheung Jan 23 '20 at 10:06

0 Answers0