bnomei / kirby3-mysql-cachedriver
MySQL based Cache-Driver
Installs: 22
Dependents: 0
Suggesters: 1
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:kirby-plugin
Requires
- php: >=7.4.0
- getkirby/composer-installer: ^1.1
Requires (Dev)
- getkirby/cms: ^3.5
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^9.5
Suggests
- bnomei/kirby3-boost: Boost the speed of Kirby by having content files of pages (mem-)cached, with automatic unique ID, fast lookup and Tiny-URL.
- bnomei/kirby3-lapse: Cache any data until set expiration time
README
Dolphin - a MySQL Cache Driver for Kirby
Installation
- unzip master.zip as folder
site/plugins/kirby3-mysql-cachedriver
or git submodule add https://github.com/bnomei/kirby3-mysql-cachedriver.git site/plugins/kirby3-mysql-cachedriver
orcomposer require bnomei/kirby3-mysql-cachedriver
Usage
Cache methods
$cache = \Bnomei\MySQLCache::singleton(); // or $cache = dolphin(); $cache->set('key', 'value', $expireInMinutes); $value = dolphin()->get('key', $default); dolphin()->remove('key'); dolphin()->flush();
Benchmark
dolphin()->benchmark(1000);
mysql : 0.03287492121384 file : 0.11837792396545
ATTENTION: This will create and remove a lot of cache files and sqlite entries
No cache when debugging
When Kirbys global debug config is set to true
the complete plugin cache will be flushed and no caches will be read. But entries will be created. This will make you live easier – trust me.
How to use MySQL Cache with Lapse or Boost
You need to set the cache driver for the lapse plugin to mysql
.
site/config/config.php
<?php return [ 'bnomei.lapse.cache' => ['type' => 'mysql'], 'bnomei.boost.cache' => ['type' => 'mysql'], //... other options ];
Setup Content-File Cache
Use Kirby Boost to setup a cache for content files.
Settings
You can set the host, dbname, username, password,... in the config.
site/config/config.php
return [ // other config settings ... 'bnomei.mysql-cachedriver.dbname' => 'YOUR-DBNAME-HERE', 'bnomei.mysql-cachedriver.username' => 'YOUR-USERNAME-HERE', 'bnomei.mysql-cachedriver.password' => 'YOUR-PASSWORD-HERE', ];
You can also set a callback if you use the dotenv Plugin.
site/config/config.php
return [ // other config settings ... 'bnomei.mysql-cachedriver.dbname' => function() { return env('MYSQL_DBNAME'); }, 'bnomei.mysql-cachedriver.username' => function() { return env('MYSQL_USERNAME'); }, 'bnomei.mysql-cachedriver.password' => function() { return env('MYSQL_PASSWORD'); }, ];
Dependencies
- PHP MySQL extension
Disclaimer
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.
License
It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.