-
Notifications
You must be signed in to change notification settings - Fork 65
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
API Enable persistent FileHashCaching #282
API Enable persistent FileHashCaching #282
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to customise the cache layer here: The default cache will choose APC if available, and fall back to filesystem. APC is a relatively small in memory cache, here are the defaults in my VM:
vagrant@44:/var/www/mysite/www$ php -i | grep -i apc
...
apc.entries_hint => 4096 => 4096
apc.shm_segments => 1 => 1
apc.shm_size => 32M => 32M
So by default, you can only have 4k cache entries across all caches built by SilverStripe. Most systems will have more files than that. If combined with an infinite cache lifetime (which I'm still recommending), the SHA cache entries will crowd out other ("hotter") caches over time, meaning those caches will use the slower filesystem layer.
Note that APC caches are cleared on webserver restart (or when a new VM is provisioned as part of a full deployment like in SCP). Filesystem caches are often cleared as part of a deployment as well (either by launching a new VM, or keeping the cache folder connected to a specific deployment).
I think we should only use filesystem caches for this, and leave APC to other more important things.
return $keyOrFs; | ||
} | ||
|
||
foreach ([AssetStore::VISIBILITY_PUBLIC, AssetStore::VISIBILITY_PROTECTED] as $visibility) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ignores any other settings on a filesystem adapter. I'm really keen to have non-expiring caches on those hashes, but that's assuming the visibility alone is enough of a unique cache key. In other words, changes in config
or metadata
couldn't influence the file contents. For example, an AwsS3Adapater
could have its bucket location changed (https://github.com/thephpleague/flysystem-aws-s3-v3/blob/master/src/AwsS3Adapter.php), which somehow changes the file contents. There's no toString()
method on the Filesystem
interface, and no common way to get "all the state which influences this adapter" other than spl_object_hash
.
I think that's just a limitation we need to live with, unless we want to force everyone using other flysystem adapters to implement a wrapper that adds our own interface (toString()
, getKey()
, etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're going to change your adapter settings, I don't think it's an unreasonable expectation that you should flush your settings as well. In most cases you'll have to do that anyway to have your new settings take affect.
In any case, if your changes are somehow causing the hash of your files to change, you'll be completely screwed any way, because your database won't know anything about those new hashes.
Actually, it's a bit more subtle: So this means APC keeps caches for less time than Filesystem caches, making it a more appropriate "hot cache". But it also means if you're setting cache lifetime to |
In-memory caches are typically more resource constrained (number of items and storage space). Give cache consumers an opt-out if they are expecting to create large caches with long lifetimes. Use case: silverstripe/silverstripe-assets#282
9f5663c
to
2d35d63
Compare
In-memory caches are typically more resource constrained (number of items and storage space). Give cache consumers an opt-out if they are expecting to create large caches with long lifetimes. Use case: silverstripe/silverstripe-assets#282
FYI I've squashed those warnings in FileIDHelperResolutionStrategyTest.php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b21bfd3 - isn't this the opposite of the fixes you've done yesterday in #287? There's other tests which started using DI, what makes this one special that it needed to be reverted, when the other ones don't?
There's still a test failure: https://travis-ci.org/silverstripe/silverstripe-assets/jobs/542541684#L883
…shingService cache
b5dfd18
to
333dbed
Compare
You can use the Injector in dataProvider methods because those get call before the manifest has been initialised. That's why I've undone those changes. I just set the defaultLifetime to 0. Looking at that last failure now. |
That last commit should make all the test go green. |
Updates the FileHashCaching to be persistent and always be on.
Parent issue
#279