Developing MUC Store Plugin

Developing MUC Store Plugin

by Ryan Panning -
Number of replies: 10

I will be developing a MUC WinCache store plugin if no one else has already started. Just a few questions on how MUC stores work:

  1. How are the different modes programmed? Theoretically, I'd like to support all modes. Dug through some code but wasn't clear..
  2. What effect do the different supports have?
    1. Does SUPPORT_MULTIPLE_IDENTIFIERS === key awareness?
    2. What exactly does key awareness mean? (I don't think WinCache would support this)
    3. For WinCache, if the max allowed memory is used, then older/stale records will be purged. Does this mean DATA_GUARANTEE is not supported? Or does it mean you don't have to specify TTL (it will exist until purged)?
  3. Any other tips & tricks before I dive in? I'm sure I'll come up with more on my own. wink

Thanks!

Average of ratings: Useful (1)
In reply to Ryan Panning

Re: Developing MUC Store Plugin

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Ryan,
you could take a look at MDL-37069 to have a reference about two examples of implemeting the same cache stores using XCache: you'll find some answers and some of your questions too.
Sam Hemelryk is The Master in this area being the architect/owner of all the MUC related stuff: I'll try to give you some replies from what is my coding experience - and you'll see in my XCache store that sometimes I've taken choices different from what coded by Sam with his XCache implementation so I could be wrong wink.

  1. IMHO MODE_REQUEST should be excluded, MODE_SESSION should be added if you think that the persistence offered by the cache service can be easily managed to purge the values when the user session will be closed. AFAIK, at the time of this post, the MUC framework doesn't do that and you are required to define a TTL outside the MUC code if you want to be conservative about "size vs hit ratio" because MODE_SESSION data have by nature a limited life time and you want those data to be flushed to free space for more persistent data (MODE_APPLICATION);
  2. SUPPORTS_*:
    1. SUPPORTS_MULTIPLE_IDENTIFIERS: read the explanation in https://github.com/moodle/moodle/tree/master/cache#store
    2. Awareness: it's up to you to implement the cache_is_key_aware interface in your WinCache store plugin if you have the support from its own API (e.g.: XCache has xcache_isset())
    3. SUPPORTS_DATA_GUARANTEE: the second, TTL should not be IMHO configured if you want to offer such support. Beware that regardless the Moodle configuration in the Cache Definition your sysad could have configured TTL at WinCache level, if possible, so the store should come with a README file explaining how the different configuration parameters at the sysad level could impact on the way the store will work in Moodle
  3. Look at the configuration of WinCache to look at what parameters should be configured by the sysad and then carefully configured in terms of what (average?) numbers to put some blocking conditions e.g. to enable the WinCache store or to add SUPPORTS_DATA_GUARANTEE

I'll review my code, to help us (you and me) in coding the "perfect" store plugin cool.

HTH,
Matteo

In reply to Ryan Panning

Re: Developing MUC Store Plugin

by Sam Hemelryk -
Hi guys,

Worth noting is that Ryan has created MDL-38987. If anyone arrives here and would like to see a WinCache plugin created please visit that issue and vote to support it.

In regards to the questions you have asked Ryan I think the answers Matteo has given a pretty much spot on.
If you've any questions don't hesitate to ask them here in the forums or on the noted issue.
No doubt Matteo or myself will be able to help you.

Many thanks
Sam
In reply to Ryan Panning

Re: Developing MUC Store Plugin

by Ryan Panning -

Great, thanks for the input! I've almost completed the WinCache plugin, just need to finish the README. Couple more questions though;

  1. Just to clarify, and from what I could tell, there technically no programmical differences between the different supported modes? So the supported modes is just a guideline for which the cache store would be a good fit for?
  2. Why would the REQUEST mode not be a good fit for WinCache/APC/xCache/etc.? It appears that APPLICATION is really the best option. SESSION can actually be handled by the session store and enabling WinCache to handle session (which I'll mention in the documentation).
  3. Should I create the tests/wincache_test.php file? I notice they exist in Moodle core cache store plugins however I didn't see them in your xcache and apc plugins.
  4. WinCache supports locking, should I implement cache_is_lockable? Not hard to do but the WinCache documentation says it could create deadlocks in PHP (naturally).
In reply to Ryan Panning

Re: Developing MUC Store Plugin

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Ryan,
here are my replies:

  1. Yes&No: a developer consuming the cache could select whatever type he likes by means of creating a cache definition BUT the choice of supporting different types will be driven by BOTH the life cycle AND the scope declared for that type. If your implementation makes things equal for all the supported mode, you can offer all of them;
  2. Request type: yes it will fit except for increasing the size of the cache - it should be destroyed at the end of the Request but you can't except using PHP static scopes - and you should need to purge the entries being per request related. The same applies for the Session type. An idea that I'd like to explore too: why not forcing TTL according with the type? Again: you can provide information in the README and the sysad will take decisions; you could also make the choice configurable by the sysad at the time of adding the store, giving a configuration panel to the store by implementing the cache_is_configurable interface;
  3. Tests: good question. You need to create what required for your store to be used when running tests: they will be used if your store will be set as the default one for at least one of the supported modes;
  4. Native locking: at the time of this post locking is managed, by default, using files so it could be a nice improvement but the WinCache documentation, as you said, suggests me that it would be wiser to create at least a configuration parameter and give the sysad the responsibility to enable such a choice, if you want to implement it.

HTH,
Matteo

In reply to Matteo Scaramuccia

Re: Developing MUC Store Plugin

by Ryan Panning -

Thanks Matteo, after reading your post and digging though the code a bit further I agree that APPLICATION mode is really the best and only fit for WinCache. Since WinCache can handle Sessions, that would basically cause the default Session store to use WinCache. And since REQUEST mode is nothing more than a PHP variable that only lives during the request, there is no reason to enable 3rd party to store that data.

For the native locking, I'm not sure how I could implement a configuration parameter/setting for the user to choose. It seems that Moodle checks if the class has extended cache_is_lockable interface. Therefore, I don't see a way to make that configurable, unless you know of another option.

I feel comfortable with what I have at this point and will package things up in the morning. Thanks again for your help!

In reply to Ryan Panning

Re: Developing MUC Store Plugin

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Ryan,
it could be possible using a Factory or falling back to the Moodle locking system within the interface implementation but... I must recognize that it's not worth it: I guess no sysad will use it but for testing purposes, isn't it?

BTW, you can use https://moodle.org/plugins/view.php?plugin=local_codechecker to look at possible issues about the style you've adopted in writing your code: it has been always helpful for me.

HTH,
Matteo

In reply to Matteo Scaramuccia

Re: Developing MUC Store Plugin

by Ryan Panning -

Yeah, I just removed the native locking code. No other current stores support native locking anyway...

FYI, I've posted the initial plugin for review on the support ticket: MDL-38987

Thanks again! Ryan

In reply to Ryan Panning

Re: Developing MUC Store Plugin

by Ryan Panning -

WinCache also has a statistics page, similar to [Site Admin > Server > PHP info]. I'd like to add that as a plugin (as I'm sure it wouldn't be included into core). Where would the best place be to add those files? I'll also need to add a link to the admin menu, so settings.php needs to be read. Thanks!

Average of ratings: Useful (1)
In reply to Ryan Panning

Re: Developing MUC Store Plugin

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Ryan,
you could code it as a report plugin, available for just administrators.

HTH,
Matteo