9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/ocular/dsl/cache.rb', line 9
def cache_set(key, value, ttl=nil)
m = mysql()
if ttl
ttl = Time.now.to_i + ttl.to_i
end
begin
m.query("REPLACE INTO ocular_cache VALUES('#{m.escape(key)}', '#{m.escape(value)}', #{ttl == nil ? "NULL" : ttl});")
rescue Mysql2::Error => e
puts "Got #{e}, #{e.to_s}"
if e.to_s.include?("doesn't exist")
m.query("CREATE TABLE IF NOT EXISTS ocular_cache (keyname varchar(100) PRIMARY KEY, value text, expires int(11) null)")
m.query("REPLACE INTO ocular_cache VALUES('#{m.escape(key)}', '#{m.escape(value)}', #{ttl == nil ? "NULL" : ttl});")
end
end
end
|