-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add cache for the discovery loading #89
base: main
Are you sure you want to change the base?
Conversation
76b1f3a
to
efa4b22
Compare
efa4b22
to
dd904e2
Compare
dd904e2
to
f8fa3c1
Compare
$max_age = ($expire === Cache::PERMANENT) | ||
? Cache::PERMANENT | ||
: $expire - $this->time->getRequestTime(); | ||
$cacheability->mergeCacheMaxAge($max_age); |
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.
@brummbar While you are reviewing this:
I replaced the ->setCacheMaxAge()
call with ->mergeCacheMaxAge()
which is more correct here.
I had already done this in a different branch but missed to update this one accordingly.
* @return string | ||
* The full contents of discovery.xml. | ||
* | ||
* @throws \Drupal\collabora_online\Exception\CollaboraNotAvailableException | ||
* The client url cannot be retrieved. | ||
*/ | ||
public function getDiscoveryXml(): string; | ||
public function getDiscoveryXml(RefinableCacheableDependencyInterface $cacheability): string; |
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.
We are forced to add this because we are separating the cache into a different class. But it feels unneeded.
We should just put the caching inside the fetcher itself. See e.g. \Drupal\media\OEmbed\ResourceFetcher. The caching is coded inside.
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.
Btw I don't see ResourceFetcher adding any cache tags to the cache entry.
It makes sense here because the data is coming from an external source, and does not depend on any Drupal config or content. The $url
parameter might be, but that already goes into the $cache_id
.
* {@inheritdoc} | ||
*/ | ||
public function getDiscoveryXml(RefinableCacheableDependencyInterface $cacheability): string { | ||
$cached = $this->cache->get($this->cid); |
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.
We should add a configuration value that determines for how long the xml is cached. We should put a standard value of 5 minutes, which sounds quite sensible.
See https://git.drupalcode.org/project/media_avportal/-/blob/8.x-1.x/src/AvPortalClient.php?ref_type=heads#L109 for a similar approach .
use Drupal\Component\Datetime\TimeInterface; | ||
use Drupal\Core\Cache\Cache; | ||
use Drupal\Core\Cache\CacheableMetadata; | ||
use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; | ||
use Symfony\Component\ErrorHandler\ErrorHandler; | ||
|
||
/** | ||
* Service to get values from the discovery.xml. | ||
*/ | ||
class CollaboraDiscovery implements CollaboraDiscoveryInterface { |
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.
In the end this service is a value object. Probably a factory would help in retrieving either a fresh or a cached instance of it, otherwise it gets cached in the service container and doesn't get really invalidated.
That's why I would not implement any static caching at the moment. We don't want to have to know here the cache metadata regarding how the xml was retrieved.
Changes in this PR
Still missing: Additional tests to cover the caching.
Features:
Optional additional changes not in this PR:
So.. probably we don't need these optional changes.
I had these changes locally before I simplified, and pushed them instead of discarding.