Improving wpdb queries with large data

My plugin will handle large amounts of data that could could result in the queries reading over 5000 items in a database query. The admin will provide a set of CSV files that get stored/organized in the database. The user will have some common results when they go to specific pages. I can predict what that query is in most cases. I wanted to store the array of results in cache so that query is faster.

I looked into wp_cache_get, wp_cache_set, wp_cahce_delete, etc but it seems this may not be the best option since it's not persistent. The codex says I would need an extra plugin to handle persistent caching but I'd rather not require ANOTHER plugin. I could store the array serialized in the database but not sure if that's the best route for efficiency or even an acceptable workaround to the cache issue.

Topic cache database Wordpress

Category Web


Caching is Your Friend

I understand your frustration with adding another plugin, but a method for extending WordPress cache is highly recommended for any WordPress sites getting any kind of traffic. These plugins allow WordPress to store cache somewhere better suited for storing and quickly accessing this data, such as Memcache, Redis, or even in the local file structure.

  1. W3 Total Cache offers the widest variety of destinations for cache.
  2. WP Super Cache offers very quick access to file cache.
  3. Batcache offers direct access to Memcache.
  4. Redis Cache offers direct access to Redis cache.

At the end of the day, it all depends on what's available on your server.

In my opinion, wp_cache is the way to go for what you need. It will allow you to store these values for quick access later using a much faster technology than storing them in the database.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.