Skip to content

Implemented PruneableInterface on TagAwareAdapter #24075

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
wants to merge 1 commit into from

Conversation

Toflar
Copy link
Contributor

@Toflar Toflar commented Sep 3, 2017

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets See comment on #23451
License MIT
Doc PR Added a comment on symfony/symfony-docs#8209

The ChainAdapter already delegates the prune() calls. The TagAwareAdapter is a wrapping adapter too and should delegate the prune() calls just the same.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

(with minor comment)

@@ -334,4 +335,16 @@ private function getTagVersions(array $tagsByKey)

return $tagVersions;
}

/**
* @return bool
Copy link
Member

Choose a reason for hiding this comment

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

{@inheritdoc}

@nicolas-grekas
Copy link
Member

(note: should be merged in 3.4)

@Toflar Toflar force-pushed the prunable-tagawareadapater branch from 3431f4a to 130ef7b Compare September 3, 2017 15:52
@Toflar
Copy link
Contributor Author

Toflar commented Sep 3, 2017

Updated. I also wonder if we should also purge the $tagsAdapter which might be a different instance. However, I'm not sure. While thinking about this I also wondered what happens if the $defaultLifetime of the $tagsAdapter is set to some value lower than the $itemsAdapter. Tags would get killed (not only in the pruning process but also if I e.g. use the Redis adapter) and the logic would be broken, no? I guess tags should never be purged unless no item is associated with a tag anymore?

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Sep 3, 2017

About tagsAdapter, I wondered the same, and I have the same conclusion: since tags should be stored "forever", there can't be anything to prune. The code btw should bypass $defaultLifetime and force "forever", isn't it already the case?

tags should never be purged unless no item is associated with a tag anymore

true, but there is no way to have that "not used anymore" info, so nothing we can prune here (and if we could, there still would be a possible race condition, so better not look a it.)

@Toflar
Copy link
Contributor Author

Toflar commented Sep 3, 2017

isn't it already the case?

I searched the code and from what I understand, I can't see where that should happen. So I hoped maybe you could shed some light on it 😄 Imho an item is created using the createCacheItem closure and this is never touched for the $tagsAdapter. The only place where I see the default lifetime being updated is as soon as the first invalidateTags() call is executed (but only for the matching items of course). Also, I don't know how you would want to check or force this from within the TagAwareAdapter because most of the logic is not accessible from the outside (on purpose, I suppose).

true, but there is no way to have that "not used anymore" info, so nothing we can prune here (and if we could, there still would be a possible race condition, so better not look a it.)

I would like to help out here but to be honest I really have a hard time understanding exactly how the tagging works internally. The whole closure stuff makes it pretty hard to understand if you're checking out the cache component internals for the first time.

@nicolas-grekas
Copy link
Member

OK, these lines make the tags last "forever", by passing any default lifetime:
https://github.com/Toflar/symfony/blob/130ef7b6568858a7d1a18801a04a95193ab18fb8/src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php#L89-L90

So all is good PR ready.

@robfrawley
Copy link
Contributor

robfrawley commented Sep 4, 2017

Documentation in symfony/symfony-docs#8209 PR amended to include note about how TagAwareAdapter now implements PruneableInterface.

@nicolas-grekas
Copy link
Member

Thank you @Toflar.

nicolas-grekas added a commit that referenced this pull request Sep 4, 2017
…lar)

This PR was submitted for the master branch but it was merged into the 3.4 branch instead (closes #24075).

Discussion
----------

Implemented PruneableInterface on TagAwareAdapter

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | See comment on #23451
| License       | MIT
| Doc PR        | Added a comment on symfony/symfony-docs#8209

The `ChainAdapter` already delegates the `prune()` calls. The `TagAwareAdapter` is a wrapping adapter too and should delegate the `prune()` calls just the same.

Commits
-------

b635b62 Implemented PruneableInterface on TagAwareAdapter
@Toflar Toflar deleted the prunable-tagawareadapater branch September 4, 2017 20:15
@Toflar
Copy link
Contributor Author

Toflar commented Sep 20, 2017

@nicolas-grekas I have to come back on this asking a question :)

true, but there is no way to have that "not used anymore" info, so nothing we can prune here

I think that's where SQLite could help out. Can you maybe shed some light on why I would ever use the FilesystemAdapter instead of the PdoAdapter together with SQLite? I mean, it's exactly what SQLite tries to compete with: replacing plain old fopen() and co. And SQLite could tell us the "not used anymore" information. Also SQLite comes bundled with php and thus should be available everywhere (unless you explicitly disabled it).

@nicolas-grekas
Copy link
Member

For sure, the PdoAdapter is here for you :)

@Toflar
Copy link
Contributor Author

Toflar commented Sep 20, 2017

Thanks for the reply :) So I could use the PdoAdapter instead for my alternative HttpCache implementation then :)
Do you see a way how we could use that power in the TagAwareAdapter to clean up unused tag cache entries of the $tagsAdapter?

@nicolas-grekas
Copy link
Member

Right now the relationships are not known by the underlying DB so you'd need to scan it. Tags are stored as serialized PHP arrays. Not what you need I guess. This would need work to allow clearing with a SQL query.

This was referenced Oct 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants