11# Caching metadata in Symfony cache
22
3+ [ Read the associated library documentation] ( https://flysystem.thephpleague.com/docs/advanced/caching/ )
4+
35Networking and I/O are often the source of performance problems in applications.
46On top of this, Flysystem generally aims to be as reliable as possible, which
57means it will often check and validate operations before they are done. This
68involves an additional overhead on top of the classical slowness of I/O.
79
810When your application needs to scale, you may need to cache metadata in order to
9- improve performances on this level. To do this, you can use the ` cache ` adapter
10- in this bundle.
11+ improve performances on this level. To do this, you can use the ` cache ` adapter.
12+
13+ > * Note:* this adapter caches anything but the file content. This keeps the cache
14+ > small enough to be beneficial and covers all the file system inspection operations.
1115
1216### Installation
1317
@@ -17,71 +21,68 @@ composer require league/flysystem-cached-adapter
1721
1822### Usage
1923
20- ``` yaml
21- # config/packages/flysystem.yaml
24+ The cache adapter works using a source storage (from which it will read the uncached data)
25+ and a [ Symfony cache pool ] ( https://symfony.com/doc/current/reference/configuration/framework.html#pools ) .
2226
23- flysystem :
24- storages :
25- users.storage.source :
26- adapter : ' aws'
27- options :
28- client : ' aws_client_service'
29- bucket : ' bucket_name'
30- prefix : ' optional/path/prefix'
27+ Most of the time you are only going to need one of two possibilities:
3128
32- users.storage :
33- adapter : ' cache'
34- options :
35- store : ' psr6_cache_pool' # A service ID implementing Psr\Cache\CacheItemPoolInterface
36- source : ' users.storage.source'
37- ` ` `
38-
39- However, this configuration is generic. Most of the time you are only
40- going to need one of two possibilities:
41-
42- * memory cache: this cache will expire at the end of the current CLI process or
43- HTTP request ;
44- * persistant cache: this cache will only expire when you clear it ;
29+ * in-memory cache (will expire at the end of the CLI process or HTTP request) ;
30+ * persistant cache (will stay persistent in a cache backend) ;
4531
4632#### Memory caching
4733
48- To enable memory cache, you can create a dedicated service based on the Symfony
49- Cache component:
34+ To use in-memory caching, you can create a dedicated Symfony cache pool:
5035
5136``` yaml
5237# config/packages/flysystem.yaml
5338
54- services :
55- users.storage.cache :
56- class : ' Symfony\Component\Cache\Adapter\ArrayAdapter'
39+ framework :
40+ cache :
41+ pools :
42+ cache.users.storage :
43+ adapter : cache.adapter.array
44+ default_lifetime : 3600
5745
5846flysystem :
5947 storages :
60- # ...
48+ users.storage.source :
49+ adapter : ' aws'
50+ options :
51+ client : ' aws_client_service'
52+ bucket : ' bucket_name'
53+ prefix : ' optional/path/prefix'
6154
6255 users.storage :
6356 adapter : ' cache'
6457 options :
65- store : ' users.storage.cache '
58+ store : ' cache. users.storage'
6659 source : ' users.storage.source'
6760` ` `
6861
6962#### Persistent caching
7063
71- To enable persistent cache, you can either define your own service in the same way
72- as the memory cache, or rely on the ` cache.app` service provided automatically by
73- Symfony :
64+ To use persistent caching, you can either create a dedicated Symfony cache pool
65+ or use the pool ` cache.app` which is defined by default by Symfony:
7466
7567` ` ` yaml
7668# config/packages/flysystem.yaml
7769
7870flysystem:
7971 storages:
80- # ...
72+ users.storage.source:
73+ adapter: 'aws'
74+ options:
75+ client: 'aws_client_service'
76+ bucket: 'bucket_name'
77+ prefix: 'optional/path/prefix'
8178
8279 users.storage:
8380 adapter: 'cache'
8481 options:
8582 store: 'cache.app'
8683 source: 'users.storage.source'
8784` ` `
85+
86+ # # Next
87+
88+ [Configuration reference](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/5-configuration-reference.md)
0 commit comments