Module: TrackInRecordExtender
- Included in:
- TrackInRecordOrigin
- Defined in:
- lib/extenders/track_in_record_extender.rb
Instance Method Summary collapse
- #del_cache(r) ⇒ Object
-
#fetch(track_id) ⇒ Object
TIR_CACHE_VERSION = 2.
- #mfetch(track_ids, ignore_nil = false) ⇒ Object
Instance Method Details
#del_cache(r) ⇒ Object
71 72 73 74 |
# File 'lib/extenders/track_in_record_extender.rb', line 71 def del_cache(r) # REDIS.del("tir#{r.track_id}h#{TIR_CACHE_VERSION}") $xunch["track_in_record"].evict(r.track_id) end |
#fetch(track_id) ⇒ Object
TIR_CACHE_VERSION = 2
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/extenders/track_in_record_extender.rb', line 4 def fetch(track_id) # key = "tir#{track_id}h#{TIR_CACHE_VERSION}" # data = REDIS.get(key) # return Hessian2.parse(data, TrackInRecordStruct) if data # obj = TrackInRecord.shard(track_id).where(op_type: 1, track_id: track_id).first # if obj # REDIS.set(key, Hessian2.write(Hessian2::StructWrapper.new(TrackInRecordStruct, obj))) # REDIS.expire(key, 604800) # end # obj cache_server = $xunch["track_in_record"] data = cache_server.get(track_id) return data if data obj = self.shard(track_id).where(op_type: 1, track_id: track_id).first if obj cache_server.put(obj) end obj end |
#mfetch(track_ids, ignore_nil = false) ⇒ Object
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 |
# File 'lib/extenders/track_in_record_extender.rb', line 27 def mfetch(track_ids, ignore_nil = false) # return [] if track_ids.empty? # datas = REDIS.mget(track_ids.map{|track_id| "tir#{track_id}h#{TIR_CACHE_VERSION}" }) # objs = [] # datas.each_with_index do |data, i| # if data # objs << Hessian2.parse(data, TrackInRecordStruct) # else # track_id = track_ids[i] # obj = TrackInRecord.shard(track_id).where(op_type: 1, track_id: track_id).first # objs << obj # if obj # key = "tir#{track_id}h#{TIR_CACHE_VERSION}" # REDIS.set(key, Hessian2.write(Hessian2::StructWrapper.new(TrackInRecordStruct, obj))) # REDIS.expire(key, 604800) # end # end # end # objs.delete(nil) if ignore_nil # objs return [] if track_ids.empty? cache_server = $xunch["track_in_record"] datas = cache_server.multi_get(track_ids.clone) objs = [] datas.each_with_index do |data, i| if data objs << data else track_id = track_ids[i] obj = self.shard(track_id).where(op_type: 1, track_id: track_id).first objs << obj if obj cache_server.put(obj) end end end objs.delete(nil) if ignore_nil objs end |