Module: TwitterFriendly::CachingAndLogging

Included in:
Client
Defined in:
lib/twitter_friendly/caching_and_logging.rb

Defined Under Namespace

Modules: Instrumenter

Class Method Summary collapse

Class Method Details

.caching(*method_names) ⇒ Object

TODO 1つのメソッドに対して1回しか実行されないようにする 全体をキャッシュさせ、さらにロギングを行う



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/twitter_friendly/caching_and_logging.rb', line 8

def caching(*method_names)
  method_names.each do |method_name|

    define_method(method_name) do |*args|
      options = args.dup.extract_options!
      Instrumenter.start_processing(method_name, options)

      Instrumenter.complete_processing(method_name, options) do

        key = CacheKey.gen(method_name, args, hash: credentials_hash)
        @cache.fetch(key, args: [method_name, options]) do
          Instrumenter.perform_request(method_name, options) {super(*args)}
        end
      end
    end
  end
end

.logging(*root_args) ⇒ Object

全体をキャッシュせずにロギングだけを行う



27
28
29
30
31
32
33
34
35
36
# File 'lib/twitter_friendly/caching_and_logging.rb', line 27

def logging(*root_args)
  root_args.each do |method_name|
    define_method(method_name) do |*args|
      options = args.dup.extract_options!
      Instrumenter.start_processing(method_name, options)

      Instrumenter.complete_processing(method_name, options) {super(*args)}
    end
  end
end