Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
65 lines (44 sloc) 1.73 KB
moneta: |-
Here's a quick cheat sheet for wycat's moneta cache (
Instantiate the cache:
Create a Moneta::Memory cache store:
>> require 'moneta'
>> require 'moneta/memory'
>> cache =
Create a Moneta::BasicFile cache store:
>> require 'moneta'
>> require 'moneta/basic_file'
>> cache = => 'my_cache_dir')
Use the cache:
Basic Usage:
>> cache['my_key'] = 'my_value'
=> "my_value"
>> cache['my_key']
=> "my_value"
Set an expiration:
>>'my_2nd_key', 'my_2nd_value', :expires => 100)
>> cache['my_2nd_key']
=> "my_2nd_value"
The API:
Options differs per-store, and is used to set up the store.
Retrieve a key. if the key is not available, return nil.
#[]=(key, value)::
Set a value for a key. if the key is already used, clobber it. Keys set using []= will never expire.
Delete the key from the store and return the current value.
true if the key exists, false if it does not
Alias for key?
#store(key, value, options)::
Same as []=, but you can supply an :expires_in option, which will specify a number of seconds before the key should expire. In order to support the same features across all stores, only full seconds are supported.
#update_key(key, options)::
Updates an existing key with a new :expires_in option. If the key has already expired, it will not be updated.
Clear all keys in this store.