Right now I have a "Refresh" button on my page that collects some data and sends it to this method:
public static Boolean cacheData(String index, MyObject data) {
try {reportPartition.put(hash(index), data);}
catch(Exception e) {
System.debug('Problem adding data to ReportData Cache: ' + e.getMessage());
return FALSE;
}
return TRUE;
}
The method is used elsewhere and works find but for some reason right now my debug is coming back with the following Exception message:
platform cache put operation is not allowed here
The documentation page seems to confirm this shouldn't be a problem so I'm trying to determine what other factors or flags should I be looking for that could throw this exception at that time? Is there something that happens if the pagereference redirects afterwards or the page rerenders somewhere that I should be aware of?
Exception Details:
It appears the exception being thrown is Cache.PlatformCacheInvalidOperationException
which from the documentation simply says:
A cache put or remove call is made that is not allowed. For example, when calling put or remove inside a Visualforce constructor.
This is being launched tomorrow afternoon so truly appreciate an quick help I can get ;)
P.S. We had polling on as well but commented that out for now unsure if that was causing some context in which put
was not allowed
UPDATE: PageReference Within a Component As suggested from comments below I've been attempting
put()
calls throughout my application just to verify they are allowed where I expect them and at which point the context changes and they are not. Here are my current findings:
- Page - CommandButton/PageReference: Allowed all the way through process
- Component - CommandButton/PageReference: Not Allowed in the PageReference method or anything afterwards
(note: this is a complex component with sub-components within it, but not sure how that affects having a "constructor" within the pagereference. The component controller also has 2 wrapper classes, not sure if that is related)
UPDATE: Gist summary of code As per request in comments here is a summary of my code. Please don't judge it too critically. Because I could not solve my problem described here I came up with a solution I fittingly coined as "FluxCapacitor". For the sake of solving the problem because it is also constructed in the widget I figured I'd include it in this gist.
The path of execution is dashboard.page
(with Dashboard.cls as its controller), which then uses the widget.component
(with Widget.cls as its controller), and lastly the metric.component
(with MetricController.cls as its controller)
put
call inside aPageReference
method.action="{!init}"
like the documentation suggest and I then tested a Platform Cacheput()
directly in thatinit
just to make sure it would work. Making progress will update when I have more