8000 [2.3] [WIP][HttpCache] StoreHouseKeepingInteface by liuggio · Pull Request #6855 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[2.3] [WIP][HttpCache] StoreHouseKeepingInteface #6855

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 2 commits into from

Conversation

liuggio
Copy link
Contributor
@liuggio liuggio commented Jan 23, 2013
Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #4871
License MIT
Doc PR todo

I started looking for a perfect name,
from https://www.varnish-software.com/static/book/Cache_invalidation.html#smart-bans,
but BanLurkerInterface doesn't fit well and neither CleanerInterface, and PurgerInterface neither as well.
The original @fabpot 's idea was the best StoreHousekeepingInterface.

The concept is that HttpCache::clear() will call $this->store->clear();
then the creation of the command is an easy task. Any suggestion are always appreciated.

Todo:

  • submit changes to the documentation (how to create the housekeeping clear command)
  • feedback

/**
* clear all the stale entries
*
* @abstract
Copy link
Member

Choose a reason for hiding this comment

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

This annotation should be removed

@liuggio
Copy link
Contributor Author
liuggio commented Jan 24, 2013

thanks.

@liuggio
Copy link
Contributor Author
liuggio commented Jan 25, 2013

Store::clear is callable and deletes all the 'expired' files.
StoreHousekeepingInterface is similar to https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/CacheClearer/CacheClearerInterface.php, do we need another interface?

@liuggio
Copy link
Contributor Author
liuggio commented Jan 25, 2013

The script is an easy task as I said, but is correct if I create the script in the framework repo
that is totally separated from the console commands? maybe calling the script app/bin/http-cache-clear ?

feedback here as well.

@liuggio
Copy link
Contributor Author
liuggio commented Jan 27, 2013

What do you think @fabpot ? May I continue with the command and doc?
Thanks.

@liuggio
Copy link
Contributor Author
liuggio commented Feb 1, 2013

@vicb ping

@vicb
Copy link
Contributor
vicb commented Feb 1, 2013

I would prefer that this uses the yet to be defined CacheComponent (as @lsmith77 mention in a related PR).

If this PR should be integrated as an interim solution - which I don't have the power to decide, you should clean the code according to the CS.

@liuggio
Copy link
Contributor Author
liuggio commented Feb 1, 2013

fixed according with CS and squashed.

}

/**
* Deletes from disk all the stale response-header files and the response-content files
Copy link
Contributor

Choose a reason for hiding this comment

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

should end with a "."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@vicb
Copy link
Contributor
vicb commented Feb 1, 2013

If you need more info, they are at http://symfony.com/doc/current/contributing/index.html > CS / CC

@liuggio
Copy link
Contributor Author
liuggio commented Feb 1, 2013

Many thanks... squashed again.

/**
* Deletes from disk all the stale response-header files and the response-content files.
*
* @return int The number of the cleared entries
Copy link
Contributor

Choose a reason for hiding this comment

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

int => integer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:)

@liuggio
Copy link
Contributor Author
liuggio commented Feb 1, 2013

Squashed, all the comments are satisfied.

if (array_key_exists($key, $this->responseContentList)) {
return $this->responseContentList[$key] = $this->responseContentList[$key] || $need;
}
$this->responseContentList[$key] = $need;
Copy link
Contributor

Choose a reason for hiding this comment

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

you can return this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

note: responseContentList 'd be intended as a white-list of contents, it should be true if at least one request need that response (is always possible that for the same response there are more request)

CS fixies
little fix on a return value
@liuggio
Copy link
Contributor Author
liuggio commented Feb 10, 2013

In order to create the command,
Do you think is better create a command separated from app/console or is better create a symfony command?

@vicb
Copy link
Contributor
vicb commented Feb 10, 2013

Don't know if I am "you" but I think a command could be great but the command should only makes use of a service (ie no intelligence in your command). this allows some other code to call your service.

@vicb
Copy link
Contributor
vicb commented Feb 10, 2013

I mean a sf command

@liuggio
Copy link
Contributor Author
liuggio commented Feb 10, 2013

"you" is anyone who wants to share his witticism, so you are perfect for this.
The idea of putting outside is just because the logic is inside the appCache file and creating a sf command is easy and could work only for not custom appCache.

public function clear()
{
$finder = new Finder();
$finder->depth('< 5')->files()->notName('*.lck')->in($this->root . DIRECTORY_SEPARATOR . 'md');
Copy link
Contributor

Choose a reason for hiding this comment

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

using the finder looks problematic to me, it'd become very complicated to switch to the cache component or implement this in a custom store, the input data comes from a trick only possible with filesystem AFAIK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree, what do you suggest?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually here it'd be overkill, as it's an implementation relying on filesystem, there is no reason not to leverage an existing tool helping out.

I was just pointing out the fact that if the plan is to make HttpCache use the yet to come Cache component for 2.3, most of this PR would probably have to be rewritten anyway.

@bamarni
Copy link
Contributor
bamarni commented Mar 17, 2013

I'd also have a second remark, as metadata and cached content are independent (see #7361), there is also the other way round, cached content file not referenced by any metadata, this could happen when using validation, each time the page changes and becomes invalid, an other content file is created, and the old one is kept, it also happens when purging an url, the content file is kept.

So I think the problem this PR is trying to solve (storage leaks) is unavoidable, unless it also browses all the cached content files path and removes the unreferenced ones (+ maybe other cases I can't think of), having a self cleaning cache store looks very complicated, imo the best solution remains to physically purge the storage it uses on a regular basis (here for example juste delete the whole cache folder).

@liuggio
Copy link
Contributor Author
liuggio commented Mar 17, 2013

the goal of this PR is provide a command that on regular basis clear the
expired metadata and contents if it doesn't have any metadata, maybe I don
't get your comment.
On Mar 17, 2013 3:21 PM, "Bilal Amarni" notifications@github.com wrote:

I'd also have a second remark, as metadata and cached content are
independent (see #7361 #7361),
there is also the other way round, cached content file not referenced by
any metadata, this could happen when using validation, each time the page
changes and becomes invalid, an other content file is created, and the old
one is kept, it also happens when purging an url, the content file is kept.

So I think the problem this PR is trying to solve (storage leaks) is
unavoidable, unless it also browses all the cached content files path and
removes the unreferenced ones (+ other cases I can't think of), having a
self cleaning cache store looks very complicated, imo the best solution
remains to physically purge the storage it uses on a regular basis (here
for example juste delete the whole cache folder).


Reply to this email directly or view it on GitHubhttps://github.com//pull/6855#issuecomment-15023407
.

@bamarni
Copy link
Contributor
bamarni commented Mar 17, 2013

Are you sure it deletes unreferenced content files? I can't see any place where you're extracting content file paths, I might be missing something though. But let's forget about the implementation for a moment, actually I'm -1 for the feature in itself, personally I'd just delete the folder from time to time, I don't really see the need for this whole self-introspection.

Looking at the original ticket, the reporter was saying he does a vary on cookies, I'm surprised nobody asked for more details about his use case, this is not common AFAIK, it probably leads to an entry creation for each user (assuming he's using sessions for example), then why using a shared cache? When the storage size is constantly growing, I think this feature would generally just hide bad practices or the fact that filesystem isn't the most appropriate storage for the website in question.

IMO instead of introducing yet another interface heavily relying on filesystem, (I fail to see how it could be implemented with another storage driver), better would be to make the store agnostic about the way data is persisted (once the cache component will be ready), which would lead to a very powerful optimization, and then in a second step reconsider adding this feature in a more generic way.

@liuggio
Copy link
Contributor Author
liuggio commented Apr 21, 2013

This PR has 2 months,
as @vicb said in a comment above, we need to decide what to do with caching and with this PR, I'd like to finish it, but for now maybe could be closed.

it also depends from: RFC Cache component googlegroup

@OskarStark
Copy link
Contributor

any news? the feature sounds interesting to me

@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 6, 2016
@nicolas-grekas nicolas-grekas modified the milestones: 3.4, 4.1 Sep 28, 2017
@Toflar
Copy link
Contributor
Toflar commented Dec 1, 2017

Just leaving this for reference, now that we have nice Lock and Cache components :) You guys might like https://packagist.org/packages/toflar/psr6-symfony-http-cache-store :)

@nicolas-grekas nicolas-grekas modified the milestones: 4.1, next Apr 20, 2018
@fabpot
Copy link
Member
fabpot commented Sep 21, 2018

I'm going to close this one. Re-reading my comment here (#4871 (comment)), I think we should not fix this issue. One could either do the cleanup out-of-band or switch to Varnish (which sounds like the better option).

@fabpot fabpot closed this Sep 21, 2018
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.2 Nov 1, 2018
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.

9 participants
0