• Resolved Abhineet Mittal

    (@itsabhineet)


    I am using stats_get_csv function of Jetpack to retrieve page views for individual posts and displaying them on my blog. I observed that this function is in turn storing the data in wp_options table in a single cell named stats_cache and the data is cached for 300 seconds as per the function.

    That means each time I call stats_get_csv, it fetches the stats_cache, check if data has expired for that query, query wp api and returns the result.

    Now I have thousands of posts on my blog with huge traffic. And post count is increasing by hundreds every day. That means stats_get_csv is called by thousands of posts each day which would result in huge size of stats_cache. In this case, on each page load, it will be calling that huge stats_cache.

    Will this slow down my website? How big can this stats_cache be and will it be a performance issue when this stats_cache will be caching thousands of record in a single database element?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    While the size of the option won’t be an issue, if you plan on making regular requests to the WordPress.com Stats API I would recommend that you develop your own solution instead of relying on stats_get_csv().

    We do in fact have Stats endpoints you can use in the WordPress.com REST API instead of using the old Stats API:
    https://developer.wordpress.com/docs/api/1.1/get/sites/%24site/stats/post/%24post_id/

    Jetpack includes tools to help you authenticate and interact with the API. You can check this little plugin to see how it can be done:
    https://wordpress.org/plugins/post-views-for-jetpack/

    I hope this helps.

    Thread Starter Abhineet Mittal

    (@itsabhineet)

    Thank you for confirmation about size issue.
    I am using stats_get_csv() as I only need to fetch post views and that too I am caching for a long time for each individual request. This minimizes the calls to the WP API and keep the page load time of my website in check.
    Should I keep using it for now or stats_get_csv() will not be supported in near future?

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    We have no plans on deprecating the old stats API in the near future, but if you’re ever refactoring your current solution I would recommend looking at the new API. 👍

    Thread Starter Abhineet Mittal

    (@itsabhineet)

    Thank you. I will definitely explore & use the new API when I update the code in future.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Performance with huge Size of stats_cache’ is closed to new replies.