Parent

BackgrounDRb::ResultStorage

Attributes

cache[RW]

(Not documented)

storage_type[RW]

(Not documented)

worker_key[RW]

(Not documented)

worker_name[RW]

(Not documented)

Public Class Methods

new(worker_name,worker_key,storage_type = nil) click to toggle source

(Not documented)

    # File server/lib/bdrb_result_storage.rb, line 4
 4:     def initialize(worker_name,worker_key,storage_type = nil)
 5:       @worker_name = worker_name
 6:       @worker_key = worker_key
 7:       @mutex = Mutex.new
 8:       @storage_type = storage_type
 9:       @cache = (@storage_type == 'memcache') ? memcache_instance : {}
10:     end

Public Instance Methods

[](key) click to toggle source

fetch object from cache

    # File server/lib/bdrb_result_storage.rb, line 40
40:     def [] key
41:       @mutex.synchronize { @cache[gen_key(key)] }
42:     end
[]=(key,value) click to toggle source

(Not documented)

    # File server/lib/bdrb_result_storage.rb, line 44
44:     def []= key,value
45:       @mutex.synchronize { @cache[gen_key(key)] = value }
46:     end
delete(key) click to toggle source

(Not documented)

    # File server/lib/bdrb_result_storage.rb, line 48
48:     def delete key
49:       @mutex.synchronize { @cache.delete(gen_key(key)) }
50:     end
gen_key(key) click to toggle source

generate key based on worker_name and worker_key for local cache, there is no need of unique key

    # File server/lib/bdrb_result_storage.rb, line 30
30:     def gen_key key
31:       if storage_type == 'memcache'
32:         key = [worker_name,worker_key,key].compact.join('_')
33:         key
34:       else
35:         key
36:       end
37:     end
memcache_instance() click to toggle source

Initialize Memcache for result or object caching

    # File server/lib/bdrb_result_storage.rb, line 13
13:     def memcache_instance
14:       require 'memcache'
15:       memcache_options = {
16:         :c_threshold => 10_000,
17:         :compression => true,
18:         :debug => false,
19:         :namespace => 'backgroundrb_result_hash',
20:         :readonly => false,
21:         :urlencode => false
22:       }
23:       t_cache = MemCache.new(memcache_options)
24:       t_cache.servers = BDRB_CONFIG[:memcache].split(',')
25:       t_cache
26:     end
shift(key) click to toggle source

(Not documented)

    # File server/lib/bdrb_result_storage.rb, line 52
52:     def shift key
53:       val = nil
54:       @mutex.synchronize do
55:         val = @cache[key]
56:         @cache.delete(key)
57:       end
58:       return val
59:     end

secsequence

--- SEC00046

seccomment

--- ""

attributes

--- 
- name: cache
  rw: RW
  a_desc: ""
- name: storage_type
  rw: RW
  a_desc: ""
- name: worker_key
  rw: RW
  a_desc: ""
- name: worker_name
  rw: RW
  a_desc: ""

method_list

--- 
- methods: 
  - visibility: public
    aref: M000012
    name: new
    sourcecode: "    <span class=\"ruby-comment cmt\"># File server/lib/bdrb_result_storage.rb, line 4</span>\n 4:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">initialize</span>(<span class=\"ruby-identifier\">worker_name</span>,<span class=\"ruby-identifier\">worker_key</span>,<span class=\"ruby-identifier\">storage_type</span> = <span class=\"ruby-keyword kw\">nil</span>)\n 5:       <span class=\"ruby-ivar\">@worker_name</span> = <span class=\"ruby-identifier\">worker_name</span>\n 6:       <span class=\"ruby-ivar\">@worker_key</span> = <span class=\"ruby-identifier\">worker_key</span>\n 7:       <span class=\"ruby-ivar\">@mutex</span> = <span class=\"ruby-constant\">Mutex</span>.<span class=\"ruby-identifier\">new</span>\n 8:       <span class=\"ruby-ivar\">@storage_type</span> = <span class=\"ruby-identifier\">storage_type</span>\n 9:       <span class=\"ruby-ivar\">@cache</span> = (<span class=\"ruby-ivar\">@storage_type</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-value str\">'memcache'</span>) <span class=\"ruby-operator\">?</span> <span class=\"ruby-identifier\">memcache_instance</span> <span class=\"ruby-operator\">:</span> {}\n\
      10:     <span class=\"ruby-keyword kw\">end</span>"
    params: (worker_name,worker_key,storage_type = nil)
  category: Class
  type: Public
- methods: 
  - visibility: public
    aref: M000015
    name: "[]"
    sourcecode: "    <span class=\"ruby-comment cmt\"># File server/lib/bdrb_result_storage.rb, line 40</span>\n\
      40:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-operator\">[]</span> <span class=\"ruby-identifier\">key</span>\n\
      41:       <span class=\"ruby-ivar\">@mutex</span>.<span class=\"ruby-identifier\">synchronize</span> { <span class=\"ruby-ivar\">@cache</span>[<span class=\"ruby-identifier\">gen_key</span>(<span class=\"ruby-identifier\">key</span>)] }\n\
      42:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      fetch object from cache
      </p>
    params: (key)
  - visibility: public
    aref: M000016
    name: "[]="
    sourcecode: "    <span class=\"ruby-comment cmt\"># File server/lib/bdrb_result_storage.rb, line 44</span>\n\
      44:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-operator\">[]=</span> <span class=\"ruby-identifier\">key</span>,<span class=\"ruby-identifier\">value</span>\n\
      45:       <span class=\"ruby-ivar\">@mutex</span>.<span class=\"ruby-identifier\">synchronize</span> { <span class=\"ruby-ivar\">@cache</span>[<span class=\"ruby-identifier\">gen_key</span>(<span class=\"ruby-identifier\">key</span>)] = <span class=\"ruby-identifier\">value</span> }\n\
      46:     <span class=\"ruby-keyword kw\">end</span>"
    params: (key,value)
  - visibility: public
    aref: M000017
    name: delete
    sourcecode: "    <span class=\"ruby-comment cmt\"># File server/lib/bdrb_result_storage.rb, line 48</span>\n\
      48:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">delete</span> <span class=\"ruby-identifier\">key</span>\n\
      49:       <span class=\"ruby-ivar\">@mutex</span>.<span class=\"ruby-identifier\">synchronize</span> { <span class=\"ruby-ivar\">@cache</span>.<span class=\"ruby-identifier\">delete</span>(<span class=\"ruby-identifier\">gen_key</span>(<span class=\"ruby-identifier\">key</span>)) }\n\
      50:     <span class=\"ruby-keyword kw\">end</span>"
    params: (key)
  - visibility: public
    aref: M000014
    name: gen_key
    sourcecode: "    <span class=\"ruby-comment cmt\"># File server/lib/bdrb_result_storage.rb, line 30</span>\n\
      30:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">gen_key</span> <span class=\"ruby-identifier\">key</span>\n\
      31:       <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">storage_type</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-value str\">'memcache'</span>\n\
      32:         <span class=\"ruby-identifier\">key</span> = [<span class=\"ruby-identifier\">worker_name</span>,<span class=\"ruby-identifier\">worker_key</span>,<span class=\"ruby-identifier\">key</span>].<span class=\"ruby-identifier\">compact</span>.<span class=\"ruby-identifier\">join</span>(<span class=\"ruby-value str\">'_'</span>)\n\
      33:         <span class=\"ruby-identifier\">key</span>\n\
      34:       <span class=\"ruby-keyword kw\">else</span>\n\
      35:         <span class=\"ruby-identifier\">key</span>\n\
      36:       <span class=\"ruby-keyword kw\">end</span>\n\
      37:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      generate key based on worker_name and worker_key for local cache, there is
      no need of unique key
      </p>
    params: (key)
  - visibility: public
    aref: M000013
    name: memcache_instance
    sourcecode: "    <span class=\"ruby-comment cmt\"># File server/lib/bdrb_result_storage.rb, line 13</span>\n\
      13:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">memcache_instance</span>\n\
      14:       <span class=\"ruby-identifier\">require</span> <span class=\"ruby-value str\">'memcache'</span>\n\
      15:       <span class=\"ruby-identifier\">memcache_options</span> = {\n\
      16:         <span class=\"ruby-identifier\">:c_threshold</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-value\">10_000</span>,\n\
      17:         <span class=\"ruby-identifier\">:compression</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-keyword kw\">true</span>,\n\
      18:         <span class=\"ruby-identifier\">:debug</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-keyword kw\">false</span>,\n\
      19:         <span class=\"ruby-identifier\">:namespace</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-value str\">'backgroundrb_result_hash'</span>,\n\
      20:         <span class=\"ruby-identifier\">:readonly</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-keyword kw\">false</span>,\n\
      21:         <span class=\"ruby-identifier\">:urlencode</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-keyword kw\">false</span>\n\
      22:       }\n\
      23:       <span class=\"ruby-identifier\">t_cache</span> = <span class=\"ruby-constant\">MemCache</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-identifier\">memcache_options</span>)\n\
      24:       <span class=\"ruby-identifier\">t_cache</span>.<span class=\"ruby-identifier\">servers</span> = <span class=\"ruby-constant\">BDRB_CONFIG</span>[<span class=\"ruby-identifier\">:memcache</span>].<span class=\"ruby-identifier\">split</span>(<span class=\"ruby-value str\">','</span>)\n\
      25:       <span class=\"ruby-identifier\">t_cache</span>\n\
      26:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Initialize Memcache for result or object caching
      </p>
    params: ()
  - visibility: public
    aref: M000018
    name: shift
    sourcecode: "    <span class=\"ruby-comment cmt\"># File server/lib/bdrb_result_storage.rb, line 52</span>\n\
      52:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">shift</span> <span class=\"ruby-identifier\">key</span>\n\
      53:       <span class=\"ruby-identifier\">val</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      54:       <span class=\"ruby-ivar\">@mutex</span>.<span class=\"ruby-identifier\">synchronize</span> <span class=\"ruby-keyword kw\">do</span>\n\
      55:         <span class=\"ruby-identifier\">val</span> = <span class=\"ruby-ivar\">@cache</span>[<span class=\"ruby-identifier\">key</span>]\n\
      56:         <span class=\"ruby-ivar\">@cache</span>.<span class=\"ruby-identifier\">delete</span>(<span class=\"ruby-identifier\">key</span>)\n\
      57:       <span class=\"ruby-keyword kw\">end</span>\n\
      58:       <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">val</span>\n\
      59:     <span class=\"ruby-keyword kw\">end</span>"
    params: (key)
  category: Instance
  type: Public

sectitle

--- 

[Validate]

Generated with the Darkfish Rdoc Generator.