[Cppcms-users] Using cache in application constructor
Brought to you by:
artyom-beilis
From: kpeo <sla...@ya...> - 2015-11-23 10:29:45
|
Hi! We can use cache only if context exists. But in application constructor - context is not exists yet. So what we should to do, if we caching database requests and we need to load some data in application constructor? (well, cache designed for responses mostly, but it can be used internally as well - instead of external solutions). So, here we have several ways: 1. Load data on the first web-request, that assign context. Here we need some central point for all requests, where we trigger some bool variable on the first request and never load data again (one "if" costs approximately nothing for modern CPU). We have virtual void main(std::string url) in application - but it "hooked" control for all requests and don't dispatch them to attached subapps. We can call some central function in each attached subapp, to load the data for the first time - but this looks ugly by future design. 2. Disable cache in constructor, load the data, enable cache. Better then previous, but we have no function to disable cache internally. so we can: - verify has_cache() or internal variable in each call to cache. ugly by design. - return the own dummy cache realisation class, instead of cppcms cache. we can't - cache_interface is boost::nocopyable. - wrap the cppcms cache into own functions, classes, templates to use cppcms or dummy methods - possible solution. 3. Don't caching database requests at all. Most databases have own caching mechanisms, but we better know the logic of our application and also can use own small storage solutions (well, may be they should use own cache too). 4. Let the users disable/enable cache not by configuration only, but dynamically or return "false" in cache methods if context is not assigned yet - not raise the exception. I can prepare the patch for that. But is it correct by cppcms design? And may be there are some other solutions of this problem? Thanks! Regards, kpeo |