class MemcachedServer::Item

Class that wraps up a Memcached Item

Attributes

bytes[RW]

The bite size of <data_block>

@return [Integer]

cas_id[RW]

A unique integer value

@return [Integer]

data_block[RW]

Is a chunk of arbitrary 8-bit data of length <bytes>

@return [Hash]

exptime[RW]

The expiration time

@return [Integer]

flags[RW]

Is an arbitrary unsigned integer (written out in decimal)

@return [Integer]

key[RW]

The key under which the client asks to store the data

@return [String]

lock[RW]

A simple semaphore that can be used to coordinate access to shared data from multiple concurrent threads.

@return [Mutex]

Public Class Methods

new(key, flags, exptime, bytes, data_block) click to toggle source
# 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

Public Instance Methods

expired?() click to toggle source

Checks if a MemcachedServer::Item instance is expired

@return [Boolean] true if it's expired and otherwise false

# 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() click to toggle source

Gets the next cas_id value read from last_cas_id class variable

@return [Integer] The next cas_id

# 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) click to toggle source

Parses the exptime of the MemcachedServer::Item instance

@param exptime [Integer] The expiration time @return [Time, nil] The expiration time

# 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() click to toggle source

Updates the MemcachedServer::Item cas_id with the corresponding next value read from last_cas_id class variable

# File lib/memcached-server/item.rb, line 71
def update_cas_id()

    @cas_id = get_cas_id()

end