Sha256: 4a78e2e44445e6d34513e51598e04fb6c6212f42f1b92ea0f078ee03487f2d83
Contents?: true
Size: 1.02 KB
Versions: 6
Compression:
Stored size: 1.02 KB
Contents
require 'sqlite3' data_file = File.join(LIB_DIR, "+data") data_init = !File.exists?(data_file) DATABASE = SQLite3::Database.new data_file DATABASE.type_translation = true class << DATABASE DATABASE_VERSION = 1 def setup DATABASE.execute_batch %{ CREATE TABLE cache ( url text primary key, etag text, hash varchar(40), saved datetime ); CREATE TABLE upgrades ( version int primary key ); INSERT INTO upgrades VALUES (?); }, DATABASE_VERSION end def check_cache_for url etag, hash, saved = DATABASE.get_first_row("SELECT etag, hash, saved FROM cache WHERE url = ?", url) {:etag => etag, :hash => hash, :saved => saved.nil? ? 0 : Time.parse(saved.to_s).to_i} end def notify_cache_of url, etag, hash DATABASE.query %{ REPLACE INTO cache (url, etag, hash, saved) VALUES (?, ?, ?, datetime("now", "localtime")); }, url, etag, hash nil end end DATABASE.setup if data_init
Version data entries
6 entries across 6 versions & 1 rubygems