Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Cache]: Get invalid cache items #27294

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

Closed
BlackbitDevs opened this issue May 17, 2018 · 10 comments
Closed

[Cache]: Get invalid cache items #27294

BlackbitDevs opened this issue May 17, 2018 · 10 comments
Labels
Cache Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed)

Comments

@BlackbitDevs
Copy link
Contributor

Description
It would be nice of one could get invalid cache items of a tag-based cache adapter to be able to warmup a cache after some items got invalid.

Example
Database query and its result get saved as serialized object together with tag 'test'. Due to a change all cache items with tag 'test' get invalid (via TagAwareAdapter::invalidateTags(['test'])). Later on it would be nice to fetch all invalid entries to re-warmup the cache by executing the queries and fill the cache with the current values.

@BlackbitDevs BlackbitDevs changed the title Symfony Cache: Get invalid cache items [Cache]: Get invalid cache items May 17, 2018
@nicolas-grekas
Copy link
Member

I've been wondering about something like that also. Right now, I feel like doing it with "graced" items might create a high amount of complexity, requiring new methods to fetch items from graced pools, being able to deal with a mix of hard and soft deleted items (should we create a set of interfaces/methods to allow controlling hard/soft delete, etc.)?

I've recently proposed two PRs that are related:

I'm wondering if these proposed approches couldn't be enough in practice to make it unecessary to implement anything like graced items. That'd be great because that'd mean less complexity.
WDYT?

@BlackbitDevs
Copy link
Contributor Author

I think I found a way:

  1. Initially set cache expiration to 0 (as I do not know when a write operation will occur which could alter the result)
  2. When a write operation occurs, fetch all cache items by tag which could have been altered. Set their expiration date to past.
  3. In a separate process fetch all cache items and check whether they have been expired or not and re-execute database query to re-warm the cache.

Would this be possible? Especially I wonder if 2. is possible (get cache items by tag).

@nicolas-grekas
Copy link
Member

nicolas-grekas commented May 22, 2018

"2." is not possible, and I think it goes off topic actually. Being able to do that requires a relational system, which does not exist and poses scalability issues. Solvable for sure, but not in a generic way IMHO.
Btw, if you happen to be able to know which items relate to tag "foo", another way to do it is by making tag invalidation do nothing BUT send a message to another process that could then recompute items in the background. This way, no need for graced items at all, and things might be optimal as everything happens in the background.

@BlackbitDevs
Copy link
Contributor Author

BlackbitDevs commented May 22, 2018

another way to do it is by making tag invalidation do nothing BUT send a message to another process

You mean by implementing an own class which implements TagAwareAdapterInterface?

@nicolas-grekas
Copy link
Member

implementing an own class which implements TagAwareAdapterInterface

correct!

@BlackbitDevs
Copy link
Contributor Author

I underestimated your "if you happen to be able to know which items relate to a tag"

Is it possible to let AdapterInterface::getItems() return all items, regardless whether they are valid or not? Invalidated items could get isHit = false. We could introduce a second parameter $invalid = false to AdapterInterface::getItems() so there would not be a backwards incomptible change.

@nicolas-grekas
Copy link
Member

I think it's not: design wise having a well though but restricted domain is desired. E.g. fetching all items from the backend doesn't scale with millions of items...

@BlackbitDevs
Copy link
Contributor Author

BlackbitDevs commented May 23, 2018

I meant not all items in general but all items which have the given key or tags, e.g. AdapterInterface::getItems(['foo']) could return CacheItems with isHit=true (valid items) and with isHit=false (invalid items).

@nicolas-grekas
Copy link
Member

nicolas-grekas commented May 29, 2018

items which have the given key or tags

that still exposes to the scalability issue and requires storing the relation in the backend.
Varnish (which is a great example of a tagged backend) doesn't have such feature.
That's why I don't think this belongs to the caching layer (we want to have in Symfony).

@nicolas-grekas nicolas-grekas added the RFC RFC = Request For Comments (proposals about features that you want to be discussed) label Jun 5, 2018
@nicolas-grekas
Copy link
Member

Closing as "won't fix", as explained. Thanks for proposing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cache Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed)
Projects
None yet
Development

No branches or pull requests

3 participants