My sinatra application should parse an ~ 60 MB XML file. This file almost never changes: at night, cron overwrites it with another.
Are there any tricks or ways to store the analyzed file in memory as a variable so that I can read from it by incoming requests, but do not need to parse it again and again for each incoming request?
Some pseudo codes to illustrate my problem.
get '/projects/:id' return @nokigiri_object.search("//projects/project[@id=#{params[:id]}]/name/text()") end post '/projects/update' if params[:token] == "s3cr3t" @nokogiri_object = reparse_the_xml_file end end
I need to know how to create such an @nokogiri_object so that it is saved when Sinatra starts. Is this even possible? Or do I need some storage for this?
scope ruby sinatra
berkes Jun 22 '11 at 17:05 2011-06-22 17:05
source share