Skip to content
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

Making CachingStrategy available in Cache #118

Closed
tacman opened this issue Mar 8, 2024 · 9 comments · Fixed by #135
Closed

Making CachingStrategy available in Cache #118

tacman opened this issue Mar 8, 2024 · 9 comments · Fixed by #135

Comments

@tacman
Copy link
Contributor

tacman commented Mar 8, 2024

Description

I'd like to add the caching strategy to the debug toolbar, I think it's one of the most critical pieces of information. Related to #117 and #113

image

Example

Perhaps when we implement the CacheInterface with the common methods, we could add a getCacheStrategy(). But I could be completely wrong about where the strategy is defined.

@Spomky
Copy link
Member

Spomky commented Mar 8, 2024

Hi @tacman,

I've just push an update that may solve your problem.
The way the SW Compiler works has been reviewed. Now it iterates over a list of rules. It will be simpler to add rules in the future.

Also, I created a new interface SpomkyLabs\PwaBundle\Service\HasCacheStrategies and service that have this interface have the tag spomky_labs_pwa.cache_strategy.
This means you can iterate over this tag to get all cache strategies used in an application.

<?php

declare(strict_types=1);

namespace Acme;

use SpomkyLabs\PwaBundle\Service\HasCacheStrategies;

final readonly class ListCacheStrategies
{
    /**
     * @param iterable<HasCacheStrategies> $cacheStrategyServices
     */
    public function __construct(
        #[TaggedIterator('spomky_labs_pwa.cache_strategy')]
        private iterable $cacheStrategyServices,
    ) {
    }

    public function doWhatYouWant(): array
    {
        foreach($this->cacheStrategyServices as $service) {
            $strategies = $service->getCacheStrategies();
            ///
        }
    }
}

@Spomky
Copy link
Member

Spomky commented Mar 8, 2024

Note that warm cache Urls are not yet managed.
Let me know if you see other fields to add to the options property.

@Spomky
Copy link
Member

Spomky commented Mar 8, 2024

I created a command to demonstrate how it works:

symfony console pwa:cache:list-strategies

@tacman
Copy link
Contributor Author

tacman commented Mar 8, 2024

Awesome! I'll integrate it now.

@Spomky
Copy link
Member

Spomky commented Mar 9, 2024

Hi,

The URLs and plugins are now part of the returned data.
I think you will be able to build a very detailed table now.
Just ask if you need other data.

Regards.

@tacman
Copy link
Contributor Author

tacman commented Mar 9, 2024

Thanks!

I hope to have something soon, this is more complicated than I'd hoped, but I think is going to be helpful to anyone working with the bundle.

The debug toolbar is already pointing out an issue. The planet pages never changes, but the voyages do. So I want to serve the cached planet page, and make a turbo/stimulus/ajax call to /planet/3/_voyages to get the html snippet showing the voyage, which has a different cache strategy.

Or I could make an ajax call to get json or jsonld data, which might not have the appropriate extension, but will have a mime-type in the Response and of course will match /api.

I should have something to show soon. What do you think about an EventListener to populate the cacheStrategy and preload pages?

@Spomky
Copy link
Member

Spomky commented Mar 9, 2024

Yesterday I was thinking about a way to serve pages with different caching strategies. I implement that only for the purge_cache that is intended to by used when navigating.
I will change that soon to all different caching type depending on a regex

@tacman
Copy link
Contributor Author

tacman commented Mar 13, 2024

I've updated the toolbar in pwa-extra to show all the caches, not just the ones with warmUrls. There's too many tabs, though, I'm not sure how to best organize these.

image

cF=cacheFirst, nO=networkOnly, etc. The number in the badge is the warm cache count.

@Spomky Spomky linked a pull request Mar 17, 2024 that will close this issue
4 tasks
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants