Plone classic "initialization code"

I would like to add "some code" (like not persisted ramcache setting, etc.) when a plone instance has started and is ready.
I tried a subscriber on "zope.processlifetime.IProcessStarting", but it is too early.
Where is the best place to put this code ?
Thanks in advance

What do you mean by "too early" ?

Did you check zope.processlifetime.IDatabaseOpened ?
or zope.processlifetime.IDatabaseOpenedWithRoot ?

This works for me:

Note that you have to commit your changes!

1 Like

ramcache = queryUtility(IRAMCache)
ramcache.update(maxEntries=100000, maxAge=2400, cleanupInterval=600)

Does not work because ramcache is yet changed after that.

Tried a time ago but don't remember: I think some plone config (registry ?) wasn't yet loaded...

Other problem, we don't have a plone context.

zope.processlifetime.IDatabaseOpenedWithRoot is notified before IProcessStarting

You might want to pass a context to your getUtility:

Otherwise you could call zope.component.hooks.setSite (I guess it will work as well).

Thanks @alert for your suggestions and the code references.
The ram cache setup is well kept after a commit.
I have added a product-config declaration with the site path.
Other operations work well after a setSite.
Thanks a lot

1 Like

Plone Foundation Code of Conduct