Download the PHP package bnomei/kirby-mongodb without Composer
On this page you can find all versions of the php package bnomei/kirby-mongodb. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package kirby-mongodb
🐎 Khulan - Kirby MongoDB
Khulan is a cache driver and content cache with NoSQL interface for Kirby using MongoDB.
Commercial Usage
Support open source!
This plugin is free but if you use it in a commercial project please consider to sponsor me or make a donation.
If my work helped you to make some cash it seems fair to me that I might get a little reward as well, right?
Be kind. Share a little. Thanks.
‐ Bruno
M | O | N | E | Y |
---|---|---|---|---|
Github sponsor | Patreon | Buy Me a Coffee | Paypal dontation | Hire me |
Installation
- unzip master.zip as folder
site/plugins/kirby-mongodb
or git submodule add https://github.com/bnomei/kirby-mongodb.git site/plugins/kirby-mongodb
orcomposer require bnomei/kirby-mongodb
MongoDB
There are various ways to install MongoDB. This is one way to do it on localhost for Mac OSX using Homebrew and MongoDB Atlas.
Usecase
The plugin caches all content files and keeps the cache up to date when you add/remove or update content. This cache will be used when constructing page/file/user objects making everything that involves model faster (even the Panel).
It will also allow you to query the content cache directly as a NoSQL database which might be very useful for some use-cases like filtering or searching content.
Setup
For each template you want to be cached you need to use a model to add the content cache logic using a trait.
site/models/default.php
[!NOTE] You can also use the trait for user models. File models are patched automatically.
Kirby's Content goes NoSQL
The plugin writes the content cache to a collection named khulan
in the database. You can query this collection
directly. It is not wrapped in an Cache object. This allows you to treat all your Kirby content as a NoSQL database.
Special Fields with [], {} and [,]
The plugin creates modified copies of a few field types to make the YAML based content from Kirby ready for queries. You can use
fieldname[]
to query for a value in an array from pages/files/user fields andfieldname{}
to query for an objectId in an array from pages/files/user fields andfieldname[,]
to query for fields in comma separated strings like tags/select/radio/checkbox/multiselect fields.
Example: Filtering and Resolving Relations
With Kirby's content cache as a NoSQL database you can do some advanced filtering. If you would do the same with Kirby's filtering on collection you would end up loading a lot pages and that is not as efficient. We can load the information we need directly from the cache without the need to load the full page object.
Why would we bother to read the content from a NoSQL based cache and not just put a cache around the native Kirby logic? Because the hard thing with caches is to know when to invalidate them. With the content cache we can query the NoSQL based cache directly and updating any model will be reflected instantly. Whereas with a cache around the native Kirby logic we would need rebuild the cache on every change (like with the pages cache).
Let's assume we have two models: film
and actor
. The film
model has a field actors
which is a pages field with
linked actor
pages. We want to list all films with their actors.
Load 1000 films and their actors, total of 6429 pages accessed in 250ms
Query the cache instead to get the same information in under 100ms
[!NOTE]
This example is from my Sakila DB kit. You can use similar queries to filter and resolve relations of files and user objects.
MongoDB Client
You can access the underlying MongoDB client directly.
Cache
You can either use the cache directly or use it as a cache driver for Kirby.
The MongoDB based cache will, compared to the default file-based cache, perform worse! This is to be expected as web-servers are optimized for handling requests to a couple of hundred files and keep them in memory.
As with regular Kirby cache you can also use the getOrSet
method to wrap your time expensive code into a closure and
only execute it when the cache is empty.
Using the MongoDB-based cache will allow you to perform NoSQL queries on the cache and do advanced stuff like filtering my tags or invalidating many cache entries at once.
[!NOTE]
Querying the cache directly is not recommended for regular use-cases. It will not check for the expiration of the cache entries and delete them automatically.
Using the Cache Driver in Kirby
You can also use the MongoDB-based cache as a cache driver for Kirby. This will allow you to use it for caching of other extensions in Kirby.
site/config/config.php
Settings
bnomei.mongodb. | Default | Description |
---|---|---|
host | 127.0.0.1 |
|
port | 27017 |
|
username | null |
|
password | null |
|
database | kirby |
you can give it any name you want and MongoDB will create it for you |
uriOptions | [] |
|
driverOptions | [] |
|
auto-clean-cache | true |
will clean the cache once before the first get() |
khulan.read | false |
read from cache is disabled by default as loading from file might be faster |
khulan.write | true |
write to cache for all models that use the ModelWithKhulan trait |
khulan.patch-files-class | true |
monkey-patch the \Kirby\CMS\Files class to use Khulan for caching its content |
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.
All versions of kirby-mongodb with dependencies
getkirby/composer-installer Version ^1.2
mongodb/mongodb Version ^1.19
ext-mongodb Version *