Class: RateLimit::MemCache

Inherits:
Object
  • Object
show all
Defined in:
lib/ratelimit/bucketbased.rb

Instance Method Summary collapse

Constructor Details

#initialize(cache_handle) ⇒ MemCache

Returns a new instance of MemCache.



167
168
169
# File 'lib/ratelimit/bucketbased.rb', line 167

def initialize(cache_handle)
	@cache = cache_handle
end

Instance Method Details

#get(name) ⇒ Object

retrieves a named bucket

  • Args :

    • name -> the name of the bucket to be retrieved

  • Returns :

    • the bucket matching the name if found, nil otherwise



176
177
178
179
180
181
182
183
184
185
# File 'lib/ratelimit/bucketbased.rb', line 176

def get(name)
	value = @cache.get(name)
	return nil unless value
	row = value.split(/\|/)
	bucket = nil
	if row
		bucket = Bucket.new(row[0],*row[1,8].map{|x| x.to_f})
	end
	bucket
end

#set(bucket) ⇒ Object Also known as: update

saves a bucket into the storage

  • Args :

    • bucket -> the Bucket to set. The name field in the Bucket option will be used as a key.

  • Returns :

    • the bucket that is provided in the Args



192
193
194
# File 'lib/ratelimit/bucketbased.rb', line 192

def set(bucket)
	@cache.set(bucket.name,bucket.values.join("|"))
end