Class: FC::Var
- Inherits:
-
Object
- Object
- FC::Var
- Defined in:
- lib/fc/var.rb
Class Attribute Summary collapse
-
.cache_time ⇒ Object
Returns the value of attribute cache_time.
Class Method Summary collapse
Class Attribute Details
.cache_time ⇒ Object
Returns the value of attribute cache_time.
6 7 8 |
# File 'lib/fc/var.rb', line 6 def cache_time @cache_time end |
Class Method Details
.get(name, default_value = nil) ⇒ Object
21 22 23 |
# File 'lib/fc/var.rb', line 21 def self.get(name, default_value = nil) get_all[name] || default_value end |
.get_all ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fc/var.rb', line 25 def self.get_all @mutex.synchronize do if !@get_all_read_time || Time.new.to_i - @get_all_read_time > cache_time @all_vars = {} FC::DB.query("SELECT * FROM #{FC::DB.prefix}vars").each do |row| @all_vars[row['name']] = row['val'] @all_vars[row['name'].to_sym] = row['val'] end @get_all_read_time = Time.new.to_i end end @all_vars end |
.set(name, val) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/fc/var.rb', line 12 def self.set(name, val) @mutex.synchronize do FC::DB.query("UPDATE #{FC::DB.prefix}vars SET val='#{Mysql2::Client.escape(val.to_s)}' WHERE name='#{Mysql2::Client.escape(name.to_s)}'") FC::DB.query("INSERT IGNORE INTO #{FC::DB.prefix}vars SET val='#{Mysql2::Client.escape(val.to_s)}', name='#{Mysql2::Client.escape(name.to_s)}'") @all_vars[name.to_s] = val.to_s @all_vars[name.to_sym] = val.to_s end end |