Page 1 of 1

LoadContentFromId(), cache, and properties.

Posted: Tue Oct 28, 2014 4:17 pm
by jimkberry
This regards CMSMS 1.11.11

I have noticed that in ContentOperations::LoadContentFromId() that if the content is found in the cache, then the loadproperties flag is ignored and the cached content is returned as is.

This is a problem if the cached content was loaded without properties but is now being requested with them.

Locally I've modified the code to reject the cache entry in this case and to fall through and load the content. This seems pretty inefficient, but there is no public API in ContentBase for loading properties into the cached object.

Or am I missing something here?

-jim

Re: LoadContentFromId(), cache, and properties.

Posted: Tue Oct 28, 2014 4:22 pm
by calguy1000
The public method GetPropertyValue() will lazy load the properties for the content object if they are not already loaded.

Generally we try to discourage loading all of the properties for all of the requested content pages in one request. This is because people tend to 'over use' content blocks and properties, therefore it gets very memory intensive once the number of pages get large.

Re: LoadContentFromId(), cache, and properties.

Posted: Tue Oct 28, 2014 5:00 pm
by jimkberry
Ok. But Properties() does not do the load.

So if I have a Content object that I've gotten with LoadContentFromID() for which I want the properties as an array (to pass to a template, for instance) I could call HasProperty("") to load them as a side-effect, then call Properties() and not have to worry about fixing the bug locally.

-jim

Re: LoadContentFromId(), cache, and properties.

Posted: Tue Oct 28, 2014 5:03 pm
by calguy1000
Yes. But just for safety purposes, you should pass in a property name (even if its an invalid one) to trigger the loading.

$mycontent_obj->HasProperty('__%%foo%%__');
return $mycontent_obj->Properties();