Class: MemcachedServer::Item
- Inherits:
-
Object
- Object
- MemcachedServer::Item
- Defined in:
- lib/memcached-server/item.rb
Overview
Class that wraps up a Memcached Item
Constant Summary collapse
- @@last_cas_id =
0
Instance Attribute Summary collapse
-
#bytes ⇒ Integer
The bite size of <data_block>.
-
#cas_id ⇒ Integer
A unique integer value.
-
#data_block ⇒ Hash
Is a chunk of arbitrary 8-bit data of length <bytes>.
-
#exptime ⇒ Integer
The expiration time.
-
#flags ⇒ Integer
Is an arbitrary unsigned integer (written out in decimal).
-
#key ⇒ String
The key under which the client asks to store the data.
-
#lock ⇒ Mutex
A simple semaphore that can be used to coordinate access to shared data from multiple concurrent threads.
Instance Method Summary collapse
-
#expired? ⇒ Boolean
Checks if a MemcachedServer::Item instance is expired.
-
#get_cas_id ⇒ Integer
Gets the next cas_id value read from #last_cas_id class variable.
-
#get_exptime(exptime) ⇒ Time?
Parses the exptime of the MemcachedServer::Item instance.
-
#initialize(key, flags, exptime, bytes, data_block) ⇒ Item
constructor
A new instance of Item.
-
#update_cas_id ⇒ Object
Updates the MemcachedServer::Item #cas_id with the corresponding next value read from #last_cas_id class variable.
Constructor Details
#initialize(key, flags, exptime, bytes, data_block) ⇒ Item
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/memcached-server/item.rb', line 43 def initialize(key, flags, exptime, bytes, data_block) @key = key @flags = flags @exptime = get_exptime(exptime) @bytes = bytes @data_block = data_block @lock = Mutex.new() end |
Instance Attribute Details
#bytes ⇒ Integer
The bite size of <data_block>
24 25 26 |
# File 'lib/memcached-server/item.rb', line 24 def bytes @bytes end |
#cas_id ⇒ Integer
A unique integer value
34 35 36 |
# File 'lib/memcached-server/item.rb', line 34 def cas_id @cas_id end |
#data_block ⇒ Hash
Is a chunk of arbitrary 8-bit data of length <bytes>
29 30 31 |
# File 'lib/memcached-server/item.rb', line 29 def data_block @data_block end |
#exptime ⇒ Integer
The expiration time
19 20 21 |
# File 'lib/memcached-server/item.rb', line 19 def exptime @exptime end |
#flags ⇒ Integer
Is an arbitrary unsigned integer (written out in decimal)
14 15 16 |
# File 'lib/memcached-server/item.rb', line 14 def flags @flags end |
#key ⇒ String
The key under which the client asks to store the data
9 10 11 |
# File 'lib/memcached-server/item.rb', line 9 def key @key end |
#lock ⇒ Mutex
A simple semaphore that can be used to coordinate access to shared data from multiple concurrent threads.
39 40 41 |
# File 'lib/memcached-server/item.rb', line 39 def lock @lock end |
Instance Method Details
#expired? ⇒ Boolean
Checks if a MemcachedServer::Item instance is expired
92 93 94 95 96 97 |
# File 'lib/memcached-server/item.rb', line 92 def expired?() return true if (!@exptime.nil?()) && (Time.now().getutc() > @exptime) return false end |
#get_cas_id ⇒ Integer
Gets the next cas_id value read from #last_cas_id class variable
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/memcached-server/item.rb', line 58 def get_cas_id() @lock.synchronize do @@last_cas_id += 1 next_id = @@last_cas_id.dup() return next_id end end |
#get_exptime(exptime) ⇒ Time?
Parses the exptime of the MemcachedServer::Item instance
81 82 83 84 85 86 87 |
# File 'lib/memcached-server/item.rb', line 81 def get_exptime(exptime) return nil if exptime == 0 return Time.now().getutc() if exptime < 0 return Time.now().getutc() + exptime end |
#update_cas_id ⇒ Object
Updates the MemcachedServer::Item #cas_id with the corresponding next value read from #last_cas_id class variable
71 72 73 74 75 |
# File 'lib/memcached-server/item.rb', line 71 def update_cas_id() @cas_id = get_cas_id() end |