Skip to content

Commit 60823f8

Browse files
committed
Add cache doc
1 parent c8c94c8 commit 60823f8

2 files changed

Lines changed: 87 additions & 1 deletion

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,87 @@
11
# Caching metadata in Symfony cache
2+
3+
Networking and I/O are often the source of performance problems in applications.
4+
On top of this, Flysystem generally aims to be as reliable as possible, which
5+
means it will often check and validate operations before they are done. This
6+
involves an additional overhead on top of the classical slowness of I/O.
7+
8+
When 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+
12+
### Installation
13+
14+
```
15+
composer require league/flysystem-cached-adapter
16+
```
17+
18+
### Usage
19+
20+
```yaml
21+
# config/packages/flysystem.yaml
22+
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'
31+
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 ;
45+
46+
#### Memory caching
47+
48+
To enable memory cache, you can create a dedicated service based on the Symfony
49+
Cache component:
50+
51+
```yaml
52+
# config/packages/flysystem.yaml
53+
54+
services:
55+
users.storage.cache:
56+
class: 'Symfony\Component\Cache\Adapter\ArrayAdapter'
57+
58+
flysystem:
59+
storages:
60+
# ...
61+
62+
users.storage:
63+
adapter: 'cache'
64+
options:
65+
store: 'users.storage.cache'
66+
source: 'users.storage.source'
67+
```
68+
69+
#### Persistent caching
70+
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:
74+
75+
```yaml
76+
# config/packages/flysystem.yaml
77+
78+
flysystem:
79+
storages:
80+
# ...
81+
82+
users.storage:
83+
adapter: 'cache'
84+
options:
85+
store: 'cache.app'
86+
source: 'users.storage.source'
87+
```

tests/Kernel/config/flysystem.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ flysystem:
5252
fs_local:
5353
adapter: 'local'
5454
options:
55-
directory: '%kernel.project_dir%/storage'
55+
directory: '/tmp/storage'
5656
lock: 0
5757
skip_links: false
5858
permissions:

0 commit comments

Comments
 (0)