TransWikia.com

Improving wpdb queries with large data

WordPress Development Asked by dcp3450 on December 3, 2021

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.

One Answer

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.

Answered by MikeNGarrett on December 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP