Permalink
Browse files

Added in a cache management/refresh task. refs #3846

  • Loading branch information...
Daz Oakley
Daz Oakley committed Oct 18, 2010
1 parent a2cf19c commit d1aee0f52a017fb9147d58937cb0d7d861d8368b
Showing with 54 additions and 1 deletion.
  1. +3 −0 Rakefile
  2. +1 −1 config/server/server.json
  3. +50 −0 tasks/cache.task
View
@@ -1,3 +1,6 @@
+# Add the lib directory to the search path
+$:.unshift( "#{File.dirname(__FILE__)}/lib" )
+
require 'bundler/setup'
desc 'Default task: run all tests'
@@ -7,7 +7,7 @@
},
"cache": {
"type": "file",
- "extra_urls_to_prime": []
+ "extra_searches_to_prime": []
},
"datasets": [
"emma-strains",
View
@@ -0,0 +1,50 @@
+begin
+ require 'martsearch'
+
+ @ms = MartSearch::Controller.instance()
+
+ namespace :cache do
+
+ desc "Clears the search cache"
+ task :clear do
+ puts "Clearing cache..."
+ @ms.cache.clear
+ end
+
+ desc "Primes the search cache"
+ task :prime do
+ puts "Priming cache..."
+
+ # Prime the browsable content (the first three pages of each option)
+ @ms.config[:server][:browsable_content].each do |name,conf|
+ puts " - browsable_content: #{conf[:display_name]}"
+
+ conf[:options].each do |option_name|
+ opts = conf[:processed_options][option_name.to_sym]
+ puts " - #{opts[:display_arg]}"
+
+ (1..3).each do |page_no|
+ @ms.search( opts[:solr_query], page_no )
+ end
+ end
+ end
+
+ # Any extra URLs to prime?
+ unless @ms.config[:server][:cache][:extra_searches_to_prime].empty?
+ puts " - extra_searches_to_prime:"
+ @ms.config[:server][:cache][:extra_searches_to_prime].each do |search_term|
+ puts " - #{search_term}"
+ @ms.search( search_term )
+ end
+ end
+ end
+
+ desc "Both clears and primes the search cache"
+ task :refresh => [ :clear, :prime ] do
+ end
+
+ end
+
+rescue LoadError
+ puts "[ERROR] Unable to load 'cache' tasks - please run 'bundle install'"
+end

0 comments on commit d1aee0f

Please sign in to comment.