Skip to content

Commit 887a4a6

Browse files
Described clearing caches in more detail (#3289)
* Described clearing caches in more detail * Updated baseline * Selfreview * Run fixer * PHPStan baseline * Mention environments and variables * Apply suggestion from @julitafalcondusza Co-authored-by: julitafalcondusza <117284672+julitafalcondusza@users.noreply.github.com> --------- Co-authored-by: julitafalcondusza <117284672+julitafalcondusza@users.noreply.github.com>
1 parent e546b04 commit 887a4a6

4 files changed

Lines changed: 71 additions & 90 deletions

File tree

docs/infrastructure_and_maintenance/cache/persistence_cache.md

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ For details on how to reuse this Cache service in your own custom code, see belo
1717

1818
## Transparent cache
1919

20-
With the persistence cache, like with the HTTP cache, [[= product_name =]] tries to follow principles of transparent caching.
21-
This can shortly be described as a cache which is invisible to the end user (admin/editors) of [[= product_name =]] where content is always returned *fresh*.
22-
In other words, there should be no need to manually clear the cache like it was frequently the case with eZ Publish 4.x.
23-
This is possible thanks to an interface that follows CRUD (Create Read Update Delete) operations per domain.
20+
With the persistence cache, like with the HTTP cache, [[= product_name =]] follows the principles of transparent caching.
21+
The cache is invisible to the end user (admin/editors) of [[= product_name =]] and content is always returned *fresh*.
2422

2523
## What is cached?
2624

@@ -46,11 +44,11 @@ To see where and how to contribute additional caches, refer to the [source code]
4644

4745
!!! note
4846

49-
Current implementation uses Symfony cache.
47+
Current implementation uses [Symfony application cache]([[= symfony_doc =]]/cache.html#system-cache-and-application-cache).
5048
It technically supports the following cache backends: [APCu, Array, Chain, Doctrine, Filesystem, PDO & Doctrine DBAL, Php Array, Proxy, Redis]([[= symfony_doc =]]/components/cache/cache_pools.html#creating-cache-pools).
51-
[[= product_name =]] officially supports only using Filesystem for single server and Redis for clustered setups.
49+
[[= product_name =]] officially supports only using Filesystem for single server and Redis/Valkey for clustered setups.
5250

53-
Use of Redis as shared cache back end is a requirement for use in clustering setup.
51+
Use of [Redis/Valkey](#redisvalkey) as shared cache backend is a requirement for use in clustering setup.
5452
For an overview of this feature, see [Clustering](clustering.md).
5553
Filesystem adapters, for example, are **not** intended to be used over a shared filesystem.
5654

@@ -233,7 +231,7 @@ And as [[= product_name =]] requires that instances use a cluster-aware cache in
233231

234232
#### With dependency injection
235233

236-
In your Symfony services configuration you can define that you require the cache service in your configuration like so:
234+
In your Symfony services configuration you can inject the cache service in your configuration like so:
237235

238236
``` yaml
239237
# yml configuration
@@ -244,41 +242,23 @@ In your Symfony services configuration you can define that you require the cache
244242

245243
This service is an instance of `Symfony\Component\Cache\Adapter\TagAwareAdapterInterface`, which extends the `Psr\Cache\CacheItemPoolInterface` interface with tagging functionality.
246244

247-
#### With service container
248-
249-
Like any other service, you can also get the cache service with the [service container](php_api.md#service-container) like so:
250-
251-
``` php
252-
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
253-
use Symfony\Component\DependencyInjection\ContainerInterface;
254-
255-
// Getting the cache service in PHP
256-
257-
/** @var ContainerInterface $container */
258-
$pool = $container->get('ibexa.cache_pool');
259-
/** @var TagAwareAdapterInterface $pool */
260-
```
261-
262245
### Using the cache service
263246

264247
Example usage of the cache service:
265248

266249
``` php
267250
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
268-
use Symfony\Component\DependencyInjection\ContainerInterface;
269251
270-
// Example
271252
/**
272253
* @var TagAwareAdapterInterface $pool
273-
* @var ContainerInterface $container
274254
* @var int $id
275255
*/
276256
$cacheItem = $pool->getItem("myApp-object-{$id}");
277257
if ($cacheItem->isHit()) {
278258
return $cacheItem->get();
279259
}
280260
281-
$myObject = $container->get('my_app.backend_service')->loadObject($id);
261+
$myObject = $myAppCustomService->loadObject($id);
282262
$cacheItem->set($myObject);
283263
$cacheItem->tag(['myApp-category-' . $myObject->categoryId]);
284264
$pool->save($cacheItem);
@@ -290,21 +270,8 @@ For more info on usage, see [Symfony Cache's documentation]([[= symfony_doc =]]/
290270

291271
### Clearing persistence cache
292272

293-
!!! caution "Always clear the persistence with `cache:pool:clear` command"
294-
295-
Running `php bin/console cache:clear` doesn't clear the persistence cache, even when you use a filesystem-based cache pool.
296-
297-
You must always clear the persistence cache by running:
298-
299-
```bash
300-
php bin/console cache:pool:clear <cache-pool>
301-
```
302-
303-
The default cache pool is named `cache.tagaware.filesystem`.
304-
The default cache pool when running Redis or Valkey is named `cache.redis`.
305-
If you have customized the persistence cache configuration, the name of your cache pool might be different.
306-
307-
Persistence cache prefixes it's cache using "ibx-". Clearing persistence cache can thus be done in the following ways:
273+
Persistence cache uses the `ibx-` prefix, declared as a container parameter called `ibexa.core.persistence.cache.tag_prefix`.
274+
You can clear the cache as in the following example:
308275

309276
``` php
310277
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
@@ -322,3 +289,5 @@ $pool->deleteItems(["ibx-ci-$contentId"]);
322289
// Symfony cache is tag-based, so you can clear all cache related to a content item like this:
323290
$pool->invalidateTags(["c-$contentId"]);
324291
```
292+
293+
To learn how to clear persistence cache when not using the PHP API, see [Clear persistence cache](devops.md#clear-persistence-cache).

docs/infrastructure_and_maintenance/devops.md

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,81 @@ description: See various tools that can help you debug your Ibexa DXP installati
66

77
## Cache clearing
88

9-
### Clearing file cache using the Symfony cache:clear command
9+
[[= product_name =]] contains multiple layer of caching that you can clear independently from each other:
1010

11-
Symfony provides a command for clearing cache.
12-
It deletes all file-based caches, which mainly consist of a Twig template, a [service container](php_api.md#service-container), and the Symfony route cache, but also everything else stored in the cache folder.
13-
Out of the box on a single-server setup this includes Content cache.
11+
- [Clear system cache](#clear-system-cache)
12+
- [Clear persistence cache](#clear-persistence-cache)
13+
- [Clear HTTP cache](#clear-http-cache)
1414

15-
For further information on the command's use, see its help text:
15+
### Clear system cache
16+
17+
[System cache]([[= symfony_doc =]]/cache.html#system-cache-and-application-cache) is separate for every [Symfony environment](environments.md) and stores information derivable from source code like compiled container, routes, or optimized classes.
18+
19+
To clear the system cache, execute the `cache:clear` command on [every web server](clustering.md) running [[= product_name =]].
20+
21+
To specify an environment, pass it by using either the `--env` option or the `APP_ENV` variable.
22+
Both the examples below clear the system cache for the `prod` environment:
23+
24+
- `APP_ENV=prod php bin/console cache:clear`
25+
- `php bin/console cache:clear --env=prod`
26+
27+
When neither the `--env` option nor the `APP_ENV` variable is set, `cache:clear` clears the system cache for the `dev` environment by default.
28+
29+
Don't run `cache:clear` as root as it can lead to issues with file ownership.
30+
31+
!!! caution "Symfony 7.4 behavior change"
32+
33+
Starting with Symfony 7.4, running `php bin/console cache:clear` or `rm -rf var/cache/*` clears only the system cache, even when you use a filesystem-based cache pool for [persistence cache](#clear-persistence-cache).
34+
You must always clear the persistence cache separately.
35+
36+
#### Clearing system cache manually
37+
38+
During development, you can clear the system cache manually by running:
1639

1740
``` bash
18-
php bin/console --env=prod cache:clear -h
41+
rm -rf var/cache/*
1942
```
2043

21-
!!! note
44+
!!! caution "Don't clear system cache manually on production"
2245

23-
If you don't specify an environment, by default `cache:clear` clears the cache for the `dev` environment.
24-
If you want to clear it for `prod` you need to use the `--env=prod` option.
46+
Manually clearing the system cache doesn't warm up the cache, resulting in a significant performance drop on the first request.
47+
To avoid this, you must not clear the cache manually in a production environment.
2548

26-
!!! caution "Clustering"
49+
### Clear persistence cache
2750

28-
In [clustering](clustering.md) setup (with several web servers), the command to clear file cache needs to be executed on every web server.
51+
[Persistence cache](persistence_cache.md) stores information about application data.
52+
53+
To clear the persistence cache, you must run:
54+
55+
``` bash
56+
php bin/console cache:pool:clear <cache-pool>
57+
```
58+
59+
The default cache pool is named `cache.tagaware.filesystem`.
60+
The default cache pool when running Redis or Valkey is named `cache.redis`.
61+
If you customized the persistence cache configuration, the name of your cache pool might be different.
62+
63+
#### Clearing persistence cache manually
64+
65+
During development, when using a filesystem-based cache pool, you can clear the application cache by running:
66+
67+
```bash
68+
rm -rf var/share/*
69+
```
2970

30-
### Clearing content cache on a cluster setup
71+
### Clear HTTP cache
3172

32-
For a [cluster](clustering.md) setup, the content cache ([HTTP cache](http_cache.md) and [Persistence cache](persistence_cache.md)) must be set up to be shared among the servers.
33-
While all relevant cache is cleared for you on repository changes when using the APIs, there might be times where you need to clear cache manually:
73+
[HTTP cache](http_cache.md) uses reverse proxies like Varnish or Fastly to store application responses controlled by [HTTP Cache headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control).
3474

35-
- Varnish: [Cache purge](reverse_proxy.md#using-varnish-or-fastly)
36-
- Persistence Cache: [Using Cache service](persistence_cache.md#using-cache-service)
75+
To clear the HTTP cache, see [Purging from command line](content_aware_cache.md#purging-from-command-line).
3776

3877
## Web Debug Toolbar
3978

4079
As of [[= product_name =]] v4.5, the [Symfony Web Debug Toolbar]([[= symfony_doc =]]/profiler.html) is no longer installed by default.
4180
To install it, run the following command:
4281

4382
```bash
44-
composer require symfony/debug-pack
83+
composer require --dev symfony/debug-pack
4584
```
4685

4786
After you have installed Symfony Web Debug Toolbar, it's available when running [[= product_name =]] in the `dev` environment.

docs/infrastructure_and_maintenance/support_and_maintenance_faq.md

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -56,34 +56,7 @@ They can be manually removed from `composer.json` now.
5656

5757
## How to clear the cache properly?
5858

59-
Clearing cache is covered by our [documentation](devops.md#cache-clearing), it applies to file and content (HTTP/persistence) cache.
60-
61-
Useful commands:
62-
63-
- clearing Symfony cache
64-
65-
```bash
66-
php bin/console cache:clear --env prod
67-
```
68-
69-
- clearing Redis/Valkey cache
70-
71-
```bash
72-
php bin/console cache:pool:clear cache.redis
73-
```
74-
75-
- clearing the Symfony cache manually
76-
77-
```bash
78-
rm -rf var/cache/*
79-
rm -rf var/share/*
80-
```
81-
82-
!!! caution "Clearing cache manually"
83-
84-
Manual cache clearing should be executed with caution, as it doesn't warm up the cache.
85-
It results in a significant performance drop on first request, so it shouldn't be called on a production environment.
86-
Besides, it could lead to issues with file ownership after running `cache:clear` as a root.
59+
See [Cache clearing](devops.md#cache-clearing) for information how to clear system, persistence, and HTTP caches.
8760

8861
## Where should I place my configuration files?
8962

phpstan-baseline.neon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ parameters:
6767
path: code_samples/_inline_php/content_management/field_types/type_and_value/4d9e52e02d6e226f71015653d598f662f6b4d4eb0af9e99b4c49d5389af19671.php
6868

6969
-
70-
message: '#^Call to an undefined method object\:\:loadObject\(\)\.$#'
71-
identifier: method.notFound
70+
message: '#^Variable \$myAppCustomService might not be defined\.$#'
71+
identifier: variable.undefined
7272
count: 1
73-
path: code_samples/_inline_php/infrastructure_and_maintenance/cache/persistence_cache/2f333548247830523074f882c44ffb2c58e158accf9fdcd50dcb4e2e86209b1f.php
73+
path: code_samples/_inline_php/infrastructure_and_maintenance/cache/persistence_cache/c27a2fe1c12bba3e9271acc67ae3a2e2d4596bf58f4d9b791aec4e564ae88259.php
7474

7575
-
7676
message: '#^Property App\\MyService\:\:\$contentService is never read, only written\.$#'

0 commit comments

Comments
 (0)