{"id":1130,"date":"2010-06-23T18:22:50","date_gmt":"2010-06-23T12:52:50","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=1130"},"modified":"2016-12-19T15:04:05","modified_gmt":"2016-12-19T09:34:05","slug":"clearing-hibernate-query-cache-in-grails","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/clearing-hibernate-query-cache-in-grails\/","title":{"rendered":"Clearing Hibernate Query Cache in Grails"},"content":{"rendered":"<p>In one of the projects, we had used Query Caching to improve the performance. However, it also meant that the updates\/inserts into a table did not get reflected immediately, i.e. something like:<\/p>\n<blockquote>\n<pre lang=\"groovy\">DomainClass.findByPropertyName(\"propertyName\", [cache: true])<\/pre>\n<\/blockquote>\n<p>returned the same list as it was, before the insertion\/updation took place. We found that this could be resolved by clearing the query cache every time an update took place. This was done in Grails by making a call:<\/p>\n<blockquote>\n<pre lang=\"groovy\">sessionFactory.queryCache.clear()<\/pre>\n<\/blockquote>\n<p>Make sure that the artefact(controller, service, taglib, job etc.) has sessionFactory injected into it using the line:<\/p>\n<blockquote>\n<pre lang=\"groovy\">def sessionFactory<\/pre>\n<\/blockquote>\n<p>Hope this helps.<\/p>\n<p>\u2013 Vivek<\/p>\n<p>vivek[at]IntelliGrape[dot]com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In one of the projects, we had used Query Caching to improve the performance. However, it also meant that the updates\/inserts into a table did not get reflected immediately, i.e. something like: DomainClass.findByPropertyName(&#8220;propertyName&#8221;, [cache: true]) returned the same list as it was, before the insertion\/updation took place. We found that this could be resolved by [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":15},"categories":[7],"tags":[118,4840,265],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1130"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=1130"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1130\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=1130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=1130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=1130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}