Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support storage of cache in an option #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mattheu
Copy link
Member

@mattheu mattheu commented Jun 24, 2024

Allow specifying storage of cache data in an option. This ensures it's persistent even after cache being flushed.

Copy link
Collaborator

@svandragt svandragt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice start but I think this needs a bit more work in the following areas:

  • The cache might be set in an option now (optionally), but the expiry time is still a cache option, which makes it unpredicatable when redis falls away. Shouldn't we move all cache operations to options?
  • Same for the lock
  • We'd have to replicate cache group deletion as option group deletion

It might be more maintainable to extend a storage class and pass that into the various functions via dependency injection so that we can simplify the number of function arguments in various places.

@svandragt svandragt self-assigned this Jun 25, 2024
This commit involves updating the StorageProvider class and related classes such as CacheStorageProvider and TransoptionStorageProvider. Changes include adding new functions for lock verification and cache group registration. Also, OptionStorageProvider was renamed to TransoptionStorageProvider and several adjustments were made to the `namespace.php` file. These updates aim to enhance the caching functionality and improve data consistency.
This change updates the variable name from "cache_group" to "group" in several function parameters for consistency and simplicity. This change affects the register function in multiple files and helps to streamline the code, making it easier to read and understand.
@svandragt
Copy link
Collaborator

svandragt commented Jun 26, 2024

I think we made the assumption that using options as a storage provider the option is stored in the database so that if the cache layer isn't there, it would keep working. but that's incorrect in the case of a site with an object-cache.

It uses the cache anyway, so when that falls away, there's nothing, and the option table will be populated for the first time. which means in our case, the fallback message is shown.

which means might as well keep the simple implementation of using the caching layer.

In particular: "This ensures it's persistent even after cache being flushed." This is incorrect as add_option uses wp_cache_set with the options group, so this is flushed as well.

@svandragt svandragt closed this Jun 26, 2024
@mattheu
Copy link
Member Author

mattheu commented Aug 1, 2024

I think we made the assumption that using options as a storage provider the option is stored in the database so that if the cache layer isn't there, it would keep working. but that's incorrect in the case of a site with an object-cache.

I don't think this is correct. Options will always update the database even if option reads are cached in Redis to keep things fast. This is not the case for transients, which you are correct will use Redis cache exclusively if available.

In this PR I stored the cached form in the options table using update_option. But I did use transients to store the cache expiry. Maybe better to use options here too to ensure behaviour is consistent.

@mattheu mattheu reopened this Aug 1, 2024
@mattheu
Copy link
Member Author

mattheu commented Aug 1, 2024

Your improvements here to have different storage providers is really nice too.

@svandragt
Copy link
Collaborator

Yeah you're right.

https://github.com/WordPress/wordpress-develop/blob/50af37a9083f003f8e98d089091d2cc428797cc5/src/wp-includes/option.php#L1120 Shows add_option inserts the option in the database before adding it to the object cache.

I'll have another look at this PR soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants