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

feat(cache): add deleteMatching method to remove multiple cache items #4567

Merged

Conversation

yassinedoghri
Copy link
Contributor

@yassinedoghri yassinedoghri commented Apr 13, 2021

Add deleteMatching() method to cache service

Description

Maintaining a big number of cache keys with dependencies to each other can be a hassle with the current existing methods in the cache service.
This feature allows for deleting multiple cache items at once using a glob pattern:

cache()->deleteMatching('some_prefix*');
cache()->deleteMatching('*some_suffix');
// etc.

To handle cache dependencies, CI4 users would be able to structure their cache items with the same key prefix and delete the whole "pack" in one go.

Initially discussed in this post: https://forum.codeigniter.com/thread-77789-post-380976.html and on Slack.

Limitations

The implementation is only effective for file and redis/predis handlers.

Because of certain limitations, memcached and wincache handlers do not implement the method.
Both would require to go through the whole cache store (if it ever could) and match each keys
against the glob pattern. That would inevitably result in performance issues.

Also, correct me if I'm wrong, I believe memcached and wincache are not used as much as file and redis handlers. That being said, knowing the limitations and documenting them well would allow users to have access to this feature. That could remove some of the heavy load of having to maintain cache items and dependencies between them.

Any feedback is welcome!

Checklist:

  • Securely signed commits
  • Component(s) with PHPdocs
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

system/Cache/CacheInterface.php Outdated Show resolved Hide resolved
system/Cache/Handlers/FileHandler.php Outdated Show resolved Hide resolved
system/Cache/Handlers/PredisHandler.php Outdated Show resolved Hide resolved
system/Cache/Handlers/DummyHandler.php Show resolved Hide resolved
Copy link
Member

@paulbalandan paulbalandan left a comment

Choose a reason for hiding this comment

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

I maintain my stance on not adding this to the interface. Following semver, minor releases should have no breaking changes.

Furthermore, please adjust your failing tests.

… at once using a glob pattern

The implementation is only effective for file and redis/predis handlers.

Because of certain limitations, memcached and wincache handlers do not implement the method.
Both would require to go through the whole cache store (if it ever could) and match each keys
against the glob pattern. That would inevitably result in performance issues.
fix memcached tests by checking if it throws an exception
@yassinedoghri
Copy link
Contributor Author

@paulbalandan I've made the requested changes. Sorry for the failing tests, didn't pay attention... I think all should be ok now, could you please take a look?

@yassinedoghri
Copy link
Contributor Author

Apparently SQLSRV tests are failing because no connection could be established to the database...

@paulbalandan paulbalandan merged commit ede6d96 into codeigniter4:develop Apr 20, 2021
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.

None yet

2 participants