Module: CachedCalls

Included in:
Salesforce::Rest::AsfRest
Defined in:
lib/Salesforce/rest/asf_rest_cached_calls.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

class methods



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/Salesforce/rest/asf_rest_cached_calls.rb', line 22

def self.included(base)
  class << base

    # xfind is the cached version of the ActiveReources Find method. You will
    # see the speed improvement with memcache turned on.
    def xfind(*arguments)
      if Rails.cache.exist? arguments
        binobj = Rails.cache.read(arguments)
        # deserialize from Json
        obj = self.name.constantize.new.from_json(binobj)
        return obj
      else
        obj = self.find(arguments)
        # Save a Json, Marshal.dump or :raw does not work
        Rails.cache.write(arguments, obj.to_json())
        return obj
      end
    end

    # Memcached version of the describe_global() method
    def xdescribe_global()
      @@memcache_id =  self.name + "/describe_global"
      if Rails.cache.exist? @@memcache_id
        binobj = Rails.cache.read(@@memcache_id)
        # deserialize from Json
        obj = HTTParty::Parser.call(binobj, :json)
        return obj
      else
        obj = self.describe_global()
        # Save a Json, Marshal.dump or :raw does not work
        Rails.cache.write(@@memcache_id, obj.body)
        return obj
      end
    end

    # Memcached version of the get_detail_info() method
    def xget_detail_info()
      @@memcache_id =  self.name + "/describe"
      if Rails.cache.exist? @@memcache_id
        binobj = Rails.cache.read(@@memcache_id)
        # deserialize from Json
        obj = HTTParty::Parser.call(binobj, :json)
        return obj
      else
        obj = self.get_detail_info()
        # Save a Json, Marshal.dump or :raw does not work
        Rails.cache.write(@@memcache_id, obj.body)
        return obj
      end
    end

    # Memcached version of the get_meta_data() method
    def ()
      @@memcache_id =  self.name + "/meta_data"
      if Rails.cache.exist? @@memcache_id
        binobj = Rails.cache.read(@@memcache_id)
        # deserialize from Json
        obj = HTTParty::Parser.call(binobj, :json)
        return obj
      else
        obj = self.()
        # Save a Json, Marshal.dump or :raw does not work
        Rails.cache.write(@@memcache_id, obj.body)
        return obj
      end
    end

    # Memcached version of the list_available_resources() method
    def xlist_available_resources()
      @@memcache_id =  self.name + "/list_resources"
      if Rails.cache.exist? @@memcache_id
        binobj = Rails.cache.read(@@memcache_id)
        # deserialize from Json
        obj = HTTParty::Parser.call(binobj, :json)
        return obj
      else
        obj = self.list_available_resources()
        # Save a Json, Marshal.dump or :raw does not work
        Rails.cache.write(@@memcache_id, obj.body)
        return obj
      end
    end

    # Memcached version of the get_version() method
    def xget_version()
      @@memcache_id =  self.name + "/get_version"
      if Rails.cache.exist? @@memcache_id
        binobj = Rails.cache.read(@@memcache_id)
        # deserialize from Json
        obj = HTTParty::Parser.call(binobj, :json)
        return obj
      else
        obj = self.get_version()
        # Save a Json, Marshal.dump or :raw does not work
        Rails.cache.write(@@memcache_id, obj.body)
        return obj
      end
    end

    # Memcached version of the run_soql() method
    def xrun_soql(query)
      @@memcache_id =  self.name + "/run_soql"
      if Rails.cache.exist? @@memcache_id
        binobj = Rails.cache.read(@@memcache_id)
        # deserialize from Json
        obj = HTTParty::Parser.call(binobj, :json)
        return obj
      else
        obj = self.run_soql(query)
        # Save a Json, Marshal.dump or :raw does not work
        Rails.cache.write(@@memcache_id, obj.body)
        return obj
      end
    end

    # Memcached version of the run_sosl() method
    def xrun_sosl(search)
      @@memcache_id =  self.name + "/run_sosl"
      if Rails.cache.exist? @@memcache_id
        binobj = Rails.cache.read(@@memcache_id)
        # deserialize from Json
        obj = HTTParty::Parser.call(binobj, :json)
        return obj
      else
        obj = self.run_sosl(search)
        # Save a Json, Marshal.dump or :raw does not work
        Rails.cache.write(@@memcache_id, obj.body)
        return obj
      end
    end
    
  end
end