createExtensions
createExtensions
is a method, which takes an object as a parameter. That object contains, cacheInstance, getPreData and getPostData. createExtensions
returns an object with new method - one which will extend the cache instance. Passed cacheInstance / getPreData / getPostData can, but not necessarily must, be used.
Example without the use of cacheInstance
Once cache instance has a plugin registered with this method, it can be used like so:
Example with the use of cacheInstance
Above method, getItems
, when passed an array of keys to it, will return an array of items (if found). Usage will look like this:
What about lifecycle of such created methods?
If you need them - you must add them. For that you will need getPreData
and getPostData
methods passed to createExtensions
.
Here's how it would look like for getItems
method, created in the previous example:
Now getItems
method is ready for preGetItems
and postGetItems
events. If you would be a creator of such a plugin, your responsibility is to provide detailed information how lifecycle of such a method looks like:
what event names are here (by convention it's the same as created method's name, prefixed by
pre
andpost
);what properties are passed in the object (2nd argument to
getPreData
andgetPostData
);what should be returned by each method (
getPreData
andgetPostData
);what is returned by newly created method - here
getItems
.
Now, this method should have some data validation etc. but this is not the case of this example.
For more information how a complete plugin should look like, head straight to writing plugins.
Last updated