{"id":199,"date":"2009-08-21T11:20:44","date_gmt":"2009-08-21T05:50:44","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=199"},"modified":"2016-12-19T15:28:11","modified_gmt":"2016-12-19T09:58:11","slug":"grails-caching-using-cron-jobs","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/grails-caching-using-cron-jobs\/","title":{"rendered":"Grails: caching using cron jobs"},"content":{"rendered":"<p><em><\/em>Hi,<\/p>\n<p>We needed to cache the result of a webservice. We were using grails 1.1.1 version and springcache plugin for caching. Unfortunately, current springcache version didn&#8217;t work with grails 1.1.1. So we decided to cache the results using cron jobs, which will run in the background after every 1hr and store the results in a list, which will have a application level scope.<\/p>\n<p>To implement this functionality, we used quartz plugin (http:\/\/grails.org\/Quartz+plugin). This made our job easier. Below I have given the code, which did caching for us :<\/p>\n<blockquote>\n<div class=\"wp_syntax\">\n<div class=\"code\">\n<pre class=\"groovy\">import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH<\/pre>\n<\/div>\n<p>class FetchRecentBlogsJob {<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0def utilService<br \/>\n\u00a0\u00a0\u00a0\u00a0 \u00a0def concurrent = false<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 def startDelay = 1000*10<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 def timeout = 1000*60*60<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0 def execute() {<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CH.config.recentBlogs = utilService.getRecentExcerptedPosts(2)<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<br \/>\n}<\/p><\/div>\n<\/blockquote>\n<p>This excute method in the above class runs after every one hour, which gets the result from the service and updates our list. The frequency at which we need to update the list can be set using number of properties as given in the documentation of quartz plugin.<\/p>\n<p>Hope this helped.<\/p>\n<p>Cheers!!<br \/>\n~~Amit Jain~~<br \/>\namit@intelligrape.com<br \/>\nhttp:\/\/www.tothenew.com\/blog\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Grails : Caching using cron jobs i.e using quartz plugin. As with grails 1.1.1 plugin springcache plugin didn&#8217;t work.<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":7},"categories":[7],"tags":[118,117,119],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/199"}],"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\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=199"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/199\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}