Class: Cassiopee::CrawlerCache
- Inherits:
-
Object
- Object
- Cassiopee::CrawlerCache
- Defined in:
- lib/cassiopee.rb
Overview
Class maning cache of results
Constant Summary collapse
- FILE_CACHE_EXT =
".sfc"
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#errors ⇒ Object
max errors.
-
#file_suffix ⇒ Object
Suffix files name/path.
-
#max_position ⇒ Object
Returns the value of attribute max_position.
-
#method ⇒ Object
search exact: 0 hamming : 1 edit : 2.
-
#min_position ⇒ Object
filter.
Instance Method Summary collapse
- #clearCache ⇒ Object
-
#initialize ⇒ CrawlerCache
constructor
A new instance of CrawlerCache.
-
#loadCache ⇒ Object
Loads cache from file.
-
#saveCache(obj) ⇒ Object
Save self to cache, with cache object set from obj.
- #setLogger(userlogger) ⇒ Object
Constructor Details
#initialize ⇒ CrawlerCache
175 176 177 |
# File 'lib/cassiopee.rb', line 175 def initialize @file_suffix = "crawler" end |
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
166 167 168 |
# File 'lib/cassiopee.rb', line 166 def cache @cache end |
#errors ⇒ Object
max errors
164 165 166 |
# File 'lib/cassiopee.rb', line 164 def errors @errors end |
#file_suffix ⇒ Object
Suffix files name/path
152 153 154 |
# File 'lib/cassiopee.rb', line 152 def file_suffix @file_suffix end |
#max_position ⇒ Object
Returns the value of attribute max_position.
161 162 163 |
# File 'lib/cassiopee.rb', line 161 def max_position @max_position end |
#method ⇒ Object
search exact: 0 hamming : 1 edit : 2
157 158 159 |
# File 'lib/cassiopee.rb', line 157 def method @method end |
#min_position ⇒ Object
filter
160 161 162 |
# File 'lib/cassiopee.rb', line 160 def min_position @min_position end |
Instance Method Details
#clearCache ⇒ Object
206 207 208 |
# File 'lib/cassiopee.rb', line 206 def clearCache File.delete(@file_suffix+FILE_CACHE_EXT) unless !File.exists?(@file_suffix+FILE_CACHE_EXT) end |
#loadCache ⇒ Object
Loads cache from file
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/cassiopee.rb', line 180 def loadCache return Array.new unless File.exists?(@file_suffix+FILE_CACHE_EXT) begin file = Zlib::GzipReader.open(@file_suffix+FILE_CACHE_EXT) rescue Zlib::GzipFile::Error file = File.open(@file_suffix+FILE_CACHE_EXT, 'r') ensure obj = Marshal.load file.read file.close if(method!=obj.method || min_position<obj.min_position || max_position>obj.max_position || errors>obj.errors) return Array.new end return filterCache(obj) end end |
#saveCache(obj) ⇒ Object
Save self to cache, with cache object set from obj
197 198 199 200 201 202 203 204 |
# File 'lib/cassiopee.rb', line 197 def saveCache(obj) self.cache = obj marshal_dump = Marshal.dump(self) sfxpos = File.new(@file_suffix+FILE_CACHE_EXT,'w') sfxpos = Zlib::GzipWriter.new(sfxpos) sfxpos.write marshal_dump sfxpos.close end |
#setLogger(userlogger) ⇒ Object
171 172 173 |
# File 'lib/cassiopee.rb', line 171 def setLogger(userlogger) $log = userlogger end |