Module: EventCache

Included in:
DrbDb
Defined in:
lib/DrbDB/EventCache.rb

Overview

this file is part of manqod manqod is distributed under the CDDL licence the owner of manqod is Dobai-Pataky Balint([email protected])

Instance Method Summary collapse

Instance Method Details

#events(gtk_object_id, force_load = false) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/DrbDB/EventCache.rb', line 21

def events(gtk_object_id,force_load=false)
  if force_load
    begin
      cache.delete("ev#{gtk_object_id}") 
    rescue Memcached::NotFound
    end
    cnt=0
    a=Hash.new
    admin.rows("select * from events where gtkobjectid = '#{gtk_object_id}'").each{|row|
      a[row['event']]=Array.new unless a.has_key?(row['event'])
      a[row['event']].push(row['command'])
      cnt+=1
    }
    cache.set("ev#{gtk_object_id}",a) if a.size>0

    einfo("loaded #{cnt.inspect} events for #{gtk_object_id.inspect}")
  end
  begin
    a=cache.set("ev#{gtk_object_id}",a)
  rescue Memcached::NotFound
    a=Array.new
  end
  a
end

#load_all_eventsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/DrbDB/EventCache.rb', line 7

def load_all_events
  cnt=0
  admin.rows("select distinct gtkobjectid from events").each{|evid|
    a=Hash.new
    admin.rows("select * from events where gtkobjectid = '#{evid['gtkobjectid']}'").each{|row|
      a[row['event']]=Array.new unless a.has_key?(row['event'])
      a[row['event']].push(row['command'])
      cnt+=1
    }
    cache.set("ev#{evid['gtkobjectid']}",a)
  }
  einfo("loaded #{cnt} events")
end