rhubarbgroup / redis-cache

A persistent object cache backend for WordPress powered by Redis. Supports Predis, PhpRedis, Relay, replication, sentinels, clustering and WP-CLI.
https://wordpress.org/plugins/redis-cache/
GNU General Public License v3.0
428 stars 149 forks source link

get_terms should be non persistent #404

Closed Stevemoretz closed 1 year ago

Stevemoretz commented 1 year ago

Hi I have a lot of

  4 => "graphql_database_graphql_cache:wp:terms:get_terms-41bf143382288f88503e60e82db37e8b-0.67671500 1671115772"
  5 => "graphql_database_graphql_cache:wp:terms:get_terms-19223ac83af72f3ee4eb3adb68918a38-0.80993200 1671115772"
  6 => "graphql_database_graphql_cache:wp:terms:get_terms-aa8871ff89a55f5c807345b5ce6bee11-0.79261900 1671115772"
  7 => "graphql_database_graphql_cache:wp:terms:get_terms-37c695843b7e38e102d79c65fd2084a9-0.75867300 1671115772"
  8 => "graphql_database_graphql_cache:wp:terms:get_terms-4c33bbc5a6b5123fcaa51b318116450c-0.75385700 1671115772"
  9 => "graphql_database_graphql_cache:wp:terms:get_terms-40f091e3fa01dbd2d0d00aaa50e0832c-0.71058600 1671115772"
  10 => "graphql_database_graphql_cache:wp:terms:get_terms-9fcc97b4625def92d155224d2b53c5ad-0.67671500 1671115772"
  11 => "graphql_database_graphql_cache:wp:terms:get_terms-4c33bbc5a6b5123fcaa51b318116450c-0.70182800 1671115772"

In redis and their ttl is set to -1 which means they stay forever, those are cached at: wp-includes/class-wp-term-query.php line 788

$cache_key    = "get_terms:$key:$last_changed";

They should be non-persistence, otherwise they will fill your redis database.

I notice you have developed a way to ignore groups, may I ask why not add a filter and send in the key alongside group to make users able to ignore by key as well?

tillkruss commented 1 year ago

This is WordPress 6.1.

If you don't like that core feature you can disable it: https://make.wordpress.org/core/2022/10/07/improvements-to-wp_query-performance-in-6-1/

If you think the keys should expire, you can open an ticket with WordPress core.

Stevemoretz commented 1 year ago

This is WordPress 6.1.

If you don't like that core feature you can disable it: https://make.wordpress.org/core/2022/10/07/improvements-to-wp_query-performance-in-6-1/

If you think the keys should expire, you can open an ticket with WordPress core.

Wait so they are different queries and for each unique query one cache gets added? so it won't jam up redis? I thought it's like the same query is just getting added on and on with different strings.

It's not a thing to like or not, I just want to make sure that it doesn't jam up the database cause if it does it needs an expiration time that makes sense.

tillkruss commented 1 year ago

WordPress calls wp_cache_set() without an expiration in your particular case, you can use WP_REDIS_MAXTTL to force all keys to use a TTL.

Stevemoretz commented 1 year ago

WordPress calls wp_cache_set() without an expiration in your particular case, you can use WP_REDIS_MAXTTL to force all keys to use a TTL.

Thanks good advice