{"id":366,"date":"2011-08-29T21:48:04","date_gmt":"2011-08-29T19:48:04","guid":{"rendered":"http:\/\/sematext.solr.pl\/?p=366"},"modified":"2020-11-11T21:48:49","modified_gmt":"2020-11-11T20:48:49","slug":"optimization-document-cache","status":"publish","type":"post","link":"https:\/\/solr.pl\/en\/2011\/08\/29\/optimization-document-cache\/","title":{"rendered":"Optimization &#8211; document cache"},"content":{"rendered":"<p>A few months ago (<a href=\"http:\/\/solr.pl\/en\/2011\/02\/07\/optimization-filter-cache\/\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>) we looked at <em>filterCache<\/em>. I&#8217;ve decided to update the optimization topic and take a look at the <em>documentCache<\/em>.<\/p>\n\n\n<!--more-->\n\n\n<h3>What it contains ?<\/h3>\n<p>So let&#8217;s start with information about the information that <em>documentCache <\/em>holds. So <em>documentCache<\/em> contain Lucene documents that were fetched from the index. So little and so much.<\/p>\n<h3>What it is used for ?<\/h3>\n<p>Every object (Lucene document) stored in <em>documentCache<\/em> contains a list of references to the fields, that are stored with the document. Thanks to this, when a document is fetched and put into the cache it doesn&#8217;t have to be fetched again while processing another query. And this is why the number of I\/O operations is reduces when rendering the query results list.<\/p>\n<h3>What to remember when using documentCache ?<\/h3>\n<p>When using <em>documentCache<\/em> you have to remember about to important things:<\/p>\n<ol>\n<li><em>documentCache<\/em> can&#8217;t be autowarmed because it operates on identifiers that change after every <em>commit <\/em>operation.<\/li>\n<li>If you use lazy field loading (<em>enableLazyFieldLoading=true<\/em>) <em>documentCache<\/em> functionality is somehow limited. This means that the document stored in the <em>documentCache<\/em> will contain only those fields that were passed to the <em>fl <\/em>parameter. If the next query will try to get additional fields for the document stored in the cache, those additional fields will be fetched from the index.<\/li>\n<\/ol>\n<h3>Definition<\/h3>\n<p>The standard <em>documentCache <\/em>definition looks like this:\n<\/p>\n<pre class=\"brush:xml\">&lt;documentCache\n      class=\"solr.FastLRUCache\"\n      size=\"16384\"\n      initialSize=\"16384\"\/&gt;<\/pre>\n<p>Let&#8217;s recall those parameters:<\/p>\n<ul>\n<li><em>class<\/em> &#8211; class implementing the cache,<\/li>\n<li><em>size<\/em> &#8211; the maximum cache size,<\/li>\n<li><em>initialSize<\/em> &#8211; initial size of the cache.<\/li>\n<\/ul>\n<h3>How to configure ?<\/h3>\n<p>The usual question about cache &#8211; what size should I set ? According to the information from Solr wiki (<a href=\"http:\/\/wiki.apache.org\/solr\/SolrCaching#documentCache\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/wiki.apache.org\/solr\/SolrCaching#documentCache<\/a>), the maximum size shouldn&#8217;t be less than the product of concurrent queries and the maximum number of documents fetched by the query. A simple relation that should ensure that Solr won&#8217;t have to fetch documents from the index during query processing.<\/p>\n<h3>Last few words<\/h3>\n<p>In the case of <em>documentCache<\/em> we don&#8217;t have to worry about how we construct our queries to properly use this cache. But please remember that <em>documentCache<\/em> requires memory, the more memory, the more field you stored in the index.<\/p>","protected":false},"excerpt":{"rendered":"<p>A few months ago (here) we looked at filterCache. I&#8217;ve decided to update the optimization topic and take a look at the documentCache.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[27],"tags":[281,408,409,367,181,164],"class_list":["post-366","post","type-post","status-publish","format-standard","hentry","category-solr-en","tag-cache-2","tag-document-2","tag-document-cache-2","tag-documentcache","tag-filter","tag-solr-2"],"_links":{"self":[{"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/posts\/366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/comments?post=366"}],"version-history":[{"count":1,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/posts\/366\/revisions"}],"predecessor-version":[{"id":367,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/posts\/366\/revisions\/367"}],"wp:attachment":[{"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/media?parent=366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/categories?post=366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/tags?post=366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}