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
{{ message }}
This repository was archived by the owner on May 18, 2025. It is now read-only.
Boost the speed of Kirby by having content files of pages (mem-)cached, with automatic unique ID, fast lookup and Tiny-URL.
10
+
Boost the speed of Kirby by having content files of pages cached, with automatic unique ID, fast lookup and Tiny-URL.
11
11
12
12
## Commerical Usage
13
13
@@ -28,10 +28,10 @@ If you have a lot of page objects (1000+) with or without relations to each othe
28
28
- It provides a very fast lookup for page objects via id, diruri or the unique id.
29
29
- It provides you with a tiny-url for page objects that have an unique id.
30
30
31
-
> This plugin is an enhanced combination of [Page Memcached](https://github.com/bnomei/kirby3-page-memcached), [AutoID](https://github.com/bnomei/kirby3-autoid/) and [Bolt](https://github.com/bnomei/kirby3-bolt).
32
-
33
31
## Setup
34
32
33
+
For each template you want to be cached you need to add the field to your blueprint AND use a model to add the content cache logic.
34
+
35
35
**site/blueprints/pages/default.yml**
36
36
```yml
37
37
preset: page
@@ -86,8 +86,30 @@ $page = boost($boostId); // will use fastest internally
86
86
```
87
87
88
88
### Modified timestamp from cache
89
+
90
+
This will try to get the modified timestamp from cache. If the page object content can be cached but currently was not, it will force a content cache write. It will return the modified timestamp of a page object or if it does not exist it will return `null`.
91
+
89
92
```php
90
-
$page = modified($somePageId);
93
+
$page = modified($somePageId); // faster
94
+
```
95
+
96
+
### Debug === read from content file (not from cache)
97
+
98
+
If you set Kirbys global debug option to `true` the plugin will not read the content cache but from the content file on disk. But it will write to the content cache so you can get debug messages if anything goes wrong with that process.
99
+
100
+
### Forcing a content cache update
101
+
102
+
You can force writing to the cache manually but doing that should not be necessary.
103
+
104
+
```php
105
+
// write content cache of a single page
106
+
$page->boost();
107
+
108
+
// write content cache of all pages in a Pages collection
How much and if you gain anything regarding performance depends on the hardware. All your content files must fit within the memory limitation. If you run into errors consider increasing the server settings or choose a different cache driver.
Kirby has [built in support](https://getkirby.com/docs/reference/system/options/cache#cache-driver) for File, Apcu, Memcached and Memory. I have created additional cache drivers for [SQLite](https://github.com/bnomei/kirby3-sqlite-cachedriver) and [Redis](https://github.com/bnomei/kirby3-redis-cachedriver).
126
+
Kirby has [built in support](https://getkirby.com/docs/reference/system/options/cache#cache-driver) for File, Apcu, Memcached and Memory. I have created additional cache drivers for [MySQL](https://github.com/bnomei/kirby3-mysql-cachedriver), [SQLite](https://github.com/bnomei/kirby3-sqlite-cachedriver) and [Redis](https://github.com/bnomei/kirby3-redis-cachedriver).
105
127
106
128
### Benchmark
107
129
108
130
The included benchmark can help you make an educated guess which is the faster cache driver. The only way to make sure is measuring in production.
109
-
Be aware that this will create and remove 2000 items cached. The benchmark will try to perform as many get operations within given timeframe (default 2 seconds per cache). The higher results are better.
131
+
Be aware that this will create and remove 1000 items cached. The benchmark will try to perform as many get operations within given timeframe (default 1 second per cache). The higher results are better.
110
132
111
133
```php
112
134
// use helpers to generate caches to compare
113
135
// rough performance level is based on my tests
114
136
$caches = [
137
+
// better
115
138
\Bnomei\BoostCache::memory(), // 100
116
139
\Bnomei\BoostCache::sqlite(), // 80
117
140
\Bnomei\BoostCache::apcu(), // 40
141
+
\Bnomei\BoostCache::mysql(), // ??
118
142
\Bnomei\BoostCache::redis(), // 30
119
143
\Bnomei\BoostCache::file(), // 10
120
144
\Bnomei\BoostCache::memcached(), // 4
145
+
// worse
121
146
];
122
147
// run the benchmark
123
148
var_dump(\Bnomei\CacheBenchmark::run($caches));
124
149
```
125
150
126
151
Memory Cache Driver will probably perform best but caches in memory only for current request and that is not really useful for this plugin. SQLite Cache Driver will perform very well since everything will be in one file and I optimized the read/write with [pragmas](https://github.com/bnomei/kirby3-sqlite-cachedriver/blob/bc3ccf56cefff7fd6b0908573ce2b4f09365c353/index.php#L20) and [wal journal mode](https://github.com/bnomei/kirby3-sqlite-cachedriver/blob/bc3ccf56cefff7fd6b0908573ce2b4f09365c353/index.php#L34).
127
152
128
-
But do not take my word for it. Run the benchmark on your production server.
153
+
> The MySQL Cache Driver is still in development but I expect it to on par with Redis and thus to be a lot SLOWER than the SQLite Cache Driver.
154
+
155
+
You can find the benchmark and demos running on server sponsored by **Kirbyzone** here:
156
+
-[Benchmark with all Drivers](https://kirby3-boost.bnomei.com)
157
+
-[Demo using SQLite Cache Driver](https://kirby3-boost-sqlite.bnomei.com)
158
+
-[Demo using MySQL Cache Driver](https://kirby3-boost-mysql.bnomei.com)
159
+
-[Demo using Redis Cache Driver](https://kirby3-boost-redis.bnomei.com)
160
+
161
+
But do not take my word for it. Download the plugin and run the benchmark on your production server.
129
162
130
163
### Config
131
164
@@ -144,7 +177,7 @@ return [
144
177
'prefix' => 'boost',
145
178
],
146
179
147
-
// example memached
180
+
// example memcached
148
181
'bnomei.boost.cache' => [
149
182
'type' => 'memcached',
150
183
'prefix' => 'boost',
@@ -199,6 +232,14 @@ You can use this plugin instead of AutoID if you did not use autoid in site obje
199
232
- Replace calls to `autoid()` with `boost()` in php code
200
233
- Replace `->fromAutoID()` with `->fromBoostID()` in php code
-[AutoID](https://github.com/bnomei/kirby3-autoid/) and
241
+
-[Bolt](https://github.com/bnomei/kirby3-bolt).
242
+
202
243
## Disclaimer
203
244
204
245
This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please [create a new issue](https://github.com/bnomei/kirby3-boost/issues/new).
0 commit comments