This questions is related to Kohana ORM AND Caching module. I use version 3.2 if it matters. I tried to research trust me, but I really couldn't find some good answer... so here it is:
What are the correct ways to use ORM::cached() and ORM::serialize() and ORM::$reload_on_wakeup?
I've seen many 2-line code examples but never anything really solid on the userguide/api...
What is the difference between enabling Cache module and 'caching' => true in Kohana::init?
Anyone has any recommended approach for the following specific situations? I have a catalogue page that upon profiling, I realized two very expensive actions:
I queried database each time for a currency model for each item, when the currency information can really be reused.
I queried database each time for each item's inventory item, this is an expensive query, which I wish I can cache until inventory level changes.
References that I found but couldn't answer fully my questions:
http://forum.kohanaframework.org/discussion/1782/tip-for-caching-orm-objects/p1
http://forum.kohanaframework.org/discussion/10600/does-kohana-orm-and-cache-work-together/p1
Just found your question, maybe too late, but maybe is useful to others:
cached, will force the Query builder to cache the DB query. It uses the KOhana:cache method (file cache) I am trying to find a workaround for this.
enables caching for the file search as says in the Kohana/Core.php file: Whether to use internal caching for [Kohana::find_file], does not apply to [Kohana::cache]. Set by [Kohana::init]
Enable caching true to speed up the file search, and enable the cache module, I am working on a way to cache the queries of DB using the instance used by the module. That would be better than using the file cache. Maybe I am missing something but stuck there right now.
Related
As the title suggests my question is pretty simple.
Is there a way to count the total number of active module instances of a specific type/kind in Joomla (with a specific module name)?
I know how to count modules in a specific module position using JModuleHelper::getModules, but that is not what I want.
I simply need to count all active modules instances of a specific type/kind.
Does anyone know how to do this (without having to do a manual MySQL query)?
I do not know if there is an official joomla way, but you can do it by having an sql query looking at
#__modules
table.
Check out this table and you will find out how easy it is.
An example sql would be:
select count(id) from #__modules where module = 'mod_login'
As far as i know there is no joomla method for this. I would recommend (if it has to be done) either
using a crawler to go through all pages of the site counting the instances.
or using a script which goes through the template php files and the database to find all active instances.
Both these methods might not be 100% reliable due to unexpected circumstances (like module being included in article or module included only after a button is clicked on) but could work if you know your site well enough.
Unfortunately there does not seem to be such a function in Joomla.
In my case I needed this to tell me whether or not a instances of this module was > 0 or not.. and my alternative solution was to simply make a module-specific function and then in the module php file check if function is already loaded.
I use Typo3 version 4.5.19 - I have a huge problem with cache_pages table - for page id=1 i have hundreds of records and database size grow higher then 500 M in less then 24 hours.
On this page I have plugin tt_news installed . I also have other different TYPO3 installation with tt_news and for them I don't have this problem . I can't figure out which is the problem.
Have any thoghts what should I do?
Probably you have various GET params that create different cache entries for each view of the same page. If you google for "typo3 cache_pages huge" you will get quite a few results, e.g. someone had a calendar plugin and it generated a page cache copy for each view of the calendar.
There are two caching mechanisms in TYPO3 < 4.6, the newer of which is called caching framework. I'm not sure which you're running on, and how it should help, but it seems related.
Also check your cHash settings; this article might be helpful: http://www.typo3-media.com/blog/chash-caching-typo3.html
I don't think your news plugin is the problem, since this would rather affect the cache_hash table.
A possible problem could be conditions in your TypoScript. If you do a condition like [globalVar = GP:L = 1], note that this will create an additional cache entry in cache_pages. You can see all your conditions at once in the TypoScript object browser.
How do I use the partial dependency caching in Kentico CMS?
Here's a very common example need I have but can't figure how to set up partial caching with dependencies correctly (in Portal mode, though I think this should apply to the other development modes too):
/Home (with a Repeater)
/News
Item 1 (so path = /News/Item-1)
Item 2 (so path = /News/Item-2)
The Home page has a Repeater web part that lists the most recent news items. It has a Path of "/%" and Document Types filter set to "CMS.News"; obviously also a "Partial cache minutes" value > 0. There is no custom code; just Portal web parts and standard document types.
What is the exact "Partial cache dependencies" string I should use so that when a third news item it is immediately reflected on the Home page, but otherwise uses the cache?
Kentico did release several blog posts including Deep dive: Cache dependencies, but I'm having difficulty applying the theory discussed there to a site. I even asked in comments there some questions, but the answers by the Kentico support there weren't really helpful.
From what I could tell in that post, they said to use node|%CurrentSite.SiteName%}|/News|childnodes which seems to have some magic keywords like node and some macro elements like {%CurrentSite.SiteName%}. (I know that all items need to be lowercase, so already I know their advice isn't real consistent. It should at least be node|%CurrentSite.SiteName%}|/news|childnodes instead. And do I need to force lowercase on the macros?) First of all, that string didn't work for me--it was still caching the Home page Top News repeater (yes, full page caching was turned off); second, how do I build a string like that and debug what it should be? The linked post does have a grid of examples, but it is confusing (to me) and not exhaustive.
Can anyone provide a good example or better blog post reference anywhere that explains this in another way?
EDIT: I realized I asked this question fairly broadly. How about if we narrow it to just answer the question: How do I determine what settings to use to cache a repeater with a dependency to changes in another folder?
The magic words you mentioned in your post are basically the keywords for particular objects. You can see them listed in the caching options description - the "node", "nodes", "nodeid" are listed there as most common for working with nodes. But below then is described the syntax for any object, where you will use that object class name.
Regarding the blog post from the Kentico's CTO and his answers in the comments, it looks like he overlooked or misunderstood your question. you are talking about partial caching and he was giving you examples on the "normal" caching settings. Macros in the touch keys are resolved (lower case or upper case does not matter) in all other caching settings but not in the partial caching. This feature will be available in the upcoming version 6.0.
So, right now you have to hard-code the site name in the touch key cache setting.
I turned on the cache debugging and looked at what cache names were being generated. I saw mine being set to...
node|{%CurrentSite.SiteName%}|/test-section/|childnodes
...which was obviously incorrect and would never work!
It looks like macros do not get resolved within the Partial Cache Dependencies property. So you can't use "{%CurrentSite.SiteName%}" in place of the site name. Here is an example of a partial cache dependency that worked for me...
node|mytestsite|/test-section/|childnodes
Using the above partial cache dependecy, the cache was refreshed as soon as I deleted a sub-item.
I'm not sure if this is the best way to go about this, but my aim is to have pagination of my lucene search results.
I thought it would make sense to run the search, store all the results in the cache, and then have a page function on my results controller that could return any particular subset of results from the cached results.
Is this a bad approach? I've never used caching of any sort, so don't know where to begin. The CI Caching Driver looked promising, but everything throws a server error. I don't know if I need to install APC, or Memcached, or what to do.
Help!
Lucene is a search engine that is built for scale. You can push it pretty far till the need arises to cache the search results. I would suggest you use the default settings and run it.
If you still feel the need for cache, first look at this Lucene FAQ and then the next level would perhaps be something on the lines of memcache.
Hope it helps!
Zend Search Lucene is indexed on the file system and as the user above has stated, built for scale. Unless you are indexing hundreds of thousands of documents, then caching is not really necessary - especially since all you would effectively be doing is taking data from one file and storing it in another.
On the other hand, if you are only storing, say, product Id in your search index and then selecting the products from the database when you get a result, it's well worth caching. This can easily be achived by using Zend_Cache.
A basic example of Zend Db caching is here:
$frontendOptions = array(
'automatic_serialization' => true
);
$backendOptions = array(
'cache_dir' => YOUR_CACHE_PATH_ON_THE_FILE_SYSTEM,
'file_name_prefix' => 'my_cache_prefix',
);
$cache = Zend_Cache::factory('Core',
'File',
$frontendOptions,
$backendOptions
);
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
This should be added to your bootstrap file in an _initDbCache (call it whatever you want) method.
Of course that is a very simple implementation and does not achieve full result caching, more information on Zend Caching with Zend Db can be found here.
I have a collection that takes significant time to load. What I would like is to cache it (APC, Memcache). It is not possible to cache the entire object (as it cannot be unserialized and it is over 1 MB). I'm thinking that caching the collection data ($col->getData() ) is the way to go, but I found no way to rebuild the object based on this array. Any clues?
Collections already have some caching built in but they need a little prompting so put this in the constructor of a collection:
$cache = Mage::app()->getCacheInstance();
$prefix = "SomeUniqueValue";
$this->initCache($cache, $prefix, array(Mage_Catalog_Model_Product::CACHE_TAG));
Choose tags appropriate to the content of the collection so that it will be flushed automatically. This way builds an ID based on the query being executed, it is most useful when the collection is filtered, ordered or paged - it avoids a version conflict.
Generally this hardly gets used because when you retrieve data you almost always end up displaying it, probably as HTML, so it makes sense to cache the output instead. Block caching is widely used and better documented.
I really don't know, but I searched for all the files that have the word "cache" in them with file names of "Collection.php" and got a few results. The most promising example to look at might be Mage_Sales_Model_Entity_Quote_Item_Collection (_getProductCollection() method). Looks like Varien_Data_Collection (which is a parent class of any magento collection) has a few cache-related methods: initCache() and _getCacheInstance().
Can't say I have used them before but might be useful someday.
Good luck.
You can get more information here: Can I use Magento's Caching layer as a Key/Value Store?
I'll be posting more info there as I find it.