thephpleague / flysystem-bundle

Symfony bundle integrating Flysystem into Symfony applications
https://github.com/thephpleague/flysystem
MIT License
357 stars 70 forks source link

Document how to cache #164

Closed tacman closed 4 weeks ago

tacman commented 3 months ago

I want to minimize calls to S3 to get a large list which rarely changes.

Is there a way to configure a cache? Perhaps DirectoryListing can be serialized and I can use the Symfony cache, but I thought there might be a built-in way, especially since Version 1 of Flysystem had a cache adapter.

Thanks.

tacman commented 3 months ago

Actually, since DirectoryListing is a generator, I expanded it to an array.

    public function storageBrowser(FilesystemOperator $defaultStorage): Response
    { 
        $images = $this->cache->get('directory', fn(CacheItem $item) =>
            iterator_to_array($defaultStorage->listContents('/', deep: true))
        );
        return $this->render(...)
    }
maxhelias commented 4 weeks ago

For the moment, I can't see any other way than to use the Symfony cache like the second comment. When I see this issue : https://github.com/thephpleague/flysystem/issues/1361, the built-in should be done in flysytem directly.