You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
No in-memory cache is used by default. We strongly recommend [configuring an in-memory cache](/developer_guides/performance/caching/#adapters) such as Redis or Memcached.
236
237
237
238
While cache objects can expire, when using filesystem caching the files are not actively pruned. For long-lived server
238
239
instances, this can become a capacity issue over time - see
Copy file name to clipboardexpand all lines: en/00_Getting_Started/03_Environment_Management.md
+1
Original file line number
Diff line number
Diff line change
@@ -126,6 +126,7 @@ Silverstripe core environment variables are listed here, though you're free to d
126
126
|`SS_DATABASE_MEMORY`| Used for [SQLite3](https://github.com/silverstripe/silverstripe-sqlite3) database connectors. |
127
127
|`SS_TRUSTED_PROXY_IPS`| IP address or CIDR range to trust proxy headers from. If left blank no proxy headers are trusted. Can be set to 'none' (trust none) or '*' (trust all). See [Request hostname forgery](/developer_guides/security/secure_coding/#request-hostname-forgery) for more information. |
128
128
|`SS_ALLOWED_HOSTS`| A comma deliminated list of hostnames the site is allowed to respond to. See [Request hostname forgery](/developer_guides/security/secure_coding/#request-hostname-forgery) for more information. |
129
+
|`SS_IN_MEMORY_CACHE_FACTORY`| The [`InMemoryCacheFactory`](api:SilverStripe\Core\Cache\InMemoryCacheFactory) class to use for instantiating in-memory cache adapters. See [caching adapters](/developer_guides/performance/caching/#adapters) for more details. |
129
130
|`SS_MANIFESTCACHE`| The manifest cache to use (defaults to file based caching). Must be a `Psr\Cache\CacheItemPoolInterface`, `Psr\SimpleCache\CacheInterface`, or `SilverStripe\Core\Cache\CacheFactory` class implementation. |
130
131
|`SS_IGNORE_DOT_ENV`| If set, the `.env` file will be ignored. This is good for live to mitigate any performance implications of loading the `.env` file. |
131
132
|`SS_BASE_URL`| The URL to use when it isn't determinable by other means (for example for CLI commands). Should either start with a protocol (e.g. `https://www.example.com`) or with a double forward slash (e.g. `//www.example.com`). |
You must have [`opcache.enable_cli`](https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.enable-cli) set to `true`
193
+
to use this cache adapter. This is so that your cache is shared between CLI and the webserver.
194
+
- `FilesystemAdapter`if the above isn't available
192
195
193
-
The library supports various [cache adapters](https://github.com/symfony/cache/tree/6.1/Adapter)
194
-
which can provide better performance, particularly in multi-server environments with shared caches like Memcached.
196
+
### Adding an in-memory cache adapter
195
197
196
-
Since we're using dependency injection to create caches,
197
-
you need to define a factory for a particular adapter,
198
-
following the `SilverStripe\Core\Cache\CacheFactory` interface.
199
-
Different adapters will require different constructor arguments.
200
-
We've written factories for the most common cache scenarios:
201
-
`FilesystemCacheFactory`, `MemcachedCacheFactory` and `ApcuCacheFactory`.
198
+
The cache adapter needs to be available before configuration has been loaded, so we use an environment variable to determine which class will be used to instantiate the in-memory cache adapter. The class must be referenced using its Fully Qualified Class Name (including namespace), and must be an instance of [`InMemoryCacheFactory`](api:SilverStripe\Core\Cache\InMemoryCacheFactory).
202
199
203
-
Example: Configure core caches to use [memcached](https://www.danga.com/memcached/),
204
-
which requires the [memcached PHP extension](https://php.net/memcached),
205
-
and takes a `MemcachedClient` instance as a constructor argument.
Silverstripe CMS comes with three in-memory cache factories you can choose from, each with their own requirements. You can of course add your own, as well.
205
+
206
+
#### Memcached cache
207
+
208
+
[Memcached](https://www.danga.com/memcached/) is a "high-performance, distributed memory object caching system". To use this cache, you must install the [memcached PHP extension](https://php.net/memcached).
209
+
210
+
You can tell the cache adapter which Memcached server(s) to connect to by defining a DSN in the `SS_MEMCACHED_DSN` environment variable.
211
+
212
+
> [!TIP]
213
+
> The format for the DSN is exactly as defined in [the Symfony documentation](https://symfony.com/doc/current/components/cache/adapters/memcached_adapter.html#configure-the-connection).
[Redis](https://redis.io/) is an "in-memory database for caching and streaming" with built-in replication and a lot of deployment options. To use this cache, you must install one of:
You can tell the cache adapter which Redis server(s) to connect to by defining a DSN in the `SS_REDIS_DSN` environment variable.
229
+
230
+
> [!TIP]
231
+
> The format for the DSN is exactly as defined in [the Symfony documentation](https://symfony.com/doc/current/components/cache/adapters/redis_adapter.html#configure-the-connection).
APCu is "an in-memory key-value store for PHP". This runs locally on the same computer as your webserver, and is only available for the webserver itself. To use this cache, you must install the [APCu PHP extension](https://www.php.net/apcu).
241
+
242
+
> [!WARNING]
243
+
> APCu cache cannot be shared with your CLI, which means flushing cache from the terminal will not flush the cache your webserver uses.
244
+
>
245
+
> The filesystem cache will still be used as a backup, which *is* shared with CLI, so flushing the cache with a web request will always flush the cache CLI uses.
246
+
247
+
We include this option because it requires very little effort to set up, so it may be appropriate for smaller projects. Just remember to always flush the cache with an HTTP request using `?flush=1`.
Copy file name to clipboardexpand all lines: en/02_Developer_Guides/16_Execution_Pipeline/02_Manifests.md
+4-2
Original file line number
Diff line number
Diff line change
@@ -20,11 +20,13 @@ which need to be generated and expired during runtime.
20
20
21
21
## Storage
22
22
23
-
By default, manifests are serialised and cached via a cache generated by the [ManifestCacheFactory](api:SilverStripe\Core\Cache\ManifestCacheFactory).
23
+
By default, manifests are serialised and cached via a cache generated by the [`ManifestCacheFactory`](api:SilverStripe\Core\Cache\ManifestCacheFactory).
24
24
This can be customised via `SS_MANIFESTCACHE` environment variable to point to either another
25
-
[CacheFactory](api:SilverStripe\Core\Cache\CacheFactory) or a class that implements the `CacheInterface`
25
+
[`CacheFactory`](api:SilverStripe\Core\Cache\CacheFactory) or a class that implements the `CacheInterface`
26
26
interface provided by [php-fig/cache](https://github.com/php-fig/cache).
27
27
28
+
See [caching](/developer_guides/performance/caching/) for more information about caching, including setting up in-memory cache adapters.
29
+
28
30
## Traversing the filesystem
29
31
30
32
Since manifests usually extract their information from files in the project root,
The [`DefaultCacheFactory`](api:SilverStripe\Core\Cache\DefaultCacheFactory) used to use APCu cache by default for your webserver - but we found this cache isn't actually shared with CLI. This means flushing cache from the CLI didn't actually flush the cache your webserver was using.
40
+
41
+
What's more, the `PHPFilesAdapter` used as a fallback wasn't enabled for CLI, which resulted in having a different filesystem cache for CLI than is used for the webserver.
42
+
43
+
We've made the following changes to resolve this problem:
44
+
45
+
- The `PHPFilesAdapter` will only be used if it's available for both the webserver *and* CLI. Otherwise, `FilesystemAdapter` will be used for both.
46
+
- There is no default in-memory cache used by `DefaultCacheFactory`.
47
+
- Cache factories have been implemented for Redis, Memcached, and APCu, with a new [`InMemoryCacheFactory`](api:SilverStripe\Core\Cache\InMemoryCacheFactory) interface available for your own implementations.
48
+
49
+
We strongly encourage you to configure an appropriate in-memory cache for your use-case. See [adding an in-memory cache adapter](/developer_guides/performance/caching/#adapters) for details.
50
+
35
51
### Changes to scaffolded form fields {#scaffolded-fields}
36
52
37
53
Some of the form fields have changed when scaffolding form fields for relations.
@@ -68,6 +84,33 @@ This release includes a number of bug fixes to improve a broad range of areas. C
68
84
69
85
Core implementations of most extension hooks such as `updateCMSFields()` now have protected visibility. Formally they had public visibility which meant they could be called directly which was not how they were intended to be used. Extension hook implementations are still able to be declared public in project code, though it is recommended that all extension hook methods are declared protected in project code to follow best practice.
70
86
87
+
### Strict typing for `Factory` implementations {#factory-strict-typing}
88
+
89
+
The [`Factory::create()`](api:SilverStripe\Core\Injector\Factory::create()) method now has strict typehinting. The first argument must be a string, and either `null` or an object must be returned.
90
+
91
+
One consequence of this is that you can no longer directly pass an instantiated anonymous class object into [`Injector::load()`](SilverStripe\Core\Injector\Injector::load()). Instead, you need to get the class name using [`get_class()`](https://www.php.net/manual/en/function.get-class.php) and pass that in as the class.
92
+
93
+
```php
94
+
use App\ClassToReplace;
95
+
use SilverStripe\Core\Injector\Injector;
96
+
97
+
// Use `get_class()` to get the class name for your anonymous class
98
+
$replacementClass = get_class(new class () {
99
+
private string $property;
100
+
101
+
public function __construct(string $value = null)
102
+
{
103
+
$this->property = $value;
104
+
}
105
+
});
106
+
107
+
Injector::inst()->load([
108
+
ClassToReplace::class => [
109
+
'class' => $replacementClass,
110
+
],
111
+
]);
112
+
```
113
+
71
114
### General changes {#api-general}
72
115
73
116
-[`DataObject::write()`](api:SilverStripe\ORM\DataObject::write()) has a new boolean `$skipValidation` parameter. This can be useful for scenarios where you want to automatically create a new record with no data initially without restricting how developers can set up their validation rules.
0 commit comments