IO::Iron::IronCache::Client - IronCache (Online Item-Value Storage) Client.
require IO::Iron::IronCache::Client; require IO::Iron::IronCache::Item; my $ironcache_client = IO::Iron::IronCache::Client->new(); # or use IO::Iron qw(get_ironcache); my $ironcache_client = get_ironcache(); # Operate with caches. my @iron_caches = $ironcache_client->get_caches(); my $iron_cache = $ironcache_client->create_cache('name' => 'My_Iron_Cache'); # Or get an existing cache. my $iron_cache = $ironcache_client->get_cache('name' => 'My_Iron_Cache'); my $cache_deleted = $ironcache_client->delete_cache('name' => 'My_Iron_Cache'); my $info = $ironcache_client->get_info_about_cache('name' => 'My_Iron_Cache'); # Operate with items. my $iron_cache_item_put = IO::Iron::IronCache::Item->new( 'value' => "10", 'expires_in' => 60, # Expires in 60 seconds. #'replace' => 1, # Only set the item if the item is already in the cache. #'add' => 1 # Only set the item if the item is not already in the cache. #'cas' => '12345' # Only set the item if there is already an item with matching key and cas. ); my $item_put_ok = $iron_cache->put('key' => 'my_item', 'item' => $iron_cache_item_put); my $item_put_new_value = $iron_cache->increment('key' => 'my_item', 'increment' => 15); my $iron_cache_item_get = $iron_cache->get('key' => 'my_item'); my $item_deleted_ok = $iron_cache->delete('key' => 'my_item'); my $items_cleared_ok = $iron_cache->clear();
See IO::Iron for requirements.
IO::Iron::IronCache is a client for the IronCache online key-value store at http://www.iron.io/. IronCache is a cloud based key-value store with a REST API. IO::Iron::IronCache::Client creates a Perl object for interacting with IronCache. All IronCache functions are available.
The class IO::Iron::IronCache::Client instantiates the 'project', IronCache access configuration.
http://www.iron.io/
IronCache is a key-value store online, usable on the principle of "Software as a Service", i.e. SaaS. It is available to Internet connecting applications via its REST interface. Built with distributed cloud applications in mind, it provides on-demand key-value storage, value persistance/expiry as requested and cloud-optimized performance. [see http://www.iron.io/]
IO::Iron::IronCache::Client is a normal Perl package meant to be used as an object.
require IO::Iron::IronCache::Client; my $iron_cache_client = IO::Iron::IronCache::Client->new();
Please see IO::Iron for further parameters and general usage.
After creating the client, the client can create a new cache (storage), get or delete an old one or get all the existing caches within the same project.
The client has all the methods which interact with the caches; the cache (object of class IO::Iron::IronCache::Cache) has methods which involve items inside the cache.
When failed to do the requested action, the methods return an exception using Perl package Exception::Class. Calling program should trap these with e.g. Perl package Try::Tiny.
# Create the cache client. require IO::Iron::IronCache::Client; my $ironcache_client = IO::Iron::IronCache::Client->new(); # Or $ironcache_client = IO::Iron::IronCache::Client->new( config => 'iron_cache.json ); # Operate with caches. # Get all the existing caches as objects of # class IO::Iron::IronCache::Cache. my @iron_caches = $ironcache_client->get_caches(); # Create a new cache object by its name. # Returns object of class IO::Iron::IronCache::Cache. my $iron_cache = $ironcache_client->create_cache('name' => 'My_Iron_Cache'); # Or get an existing cache. $iron_cache = $ironcache_client->get_cache('name' => 'My_Iron_Cache'); # Delete a cache by its name. Return 1 for success. my $cache_deleted = $ironcache_client->delete_cache('name' => 'My_Iron_Cache'); # Get info about a cache. my $info_hash = $ironcache_client->get_info_about_cache('name' => 'My_Iron_Cache'); # Operate with items. # Create an item. my $iron_cache_item_put = IO::Iron::IronCache::Item->new( 'value' => "10", 'expires_in' => 60, # Expires in 60 seconds. #'replace' => 1, # Only set the item if the item is already in the cache. #'add' => 1, # Only set the item if the item is not already in the cache. #'cas' => '12345', # Only set the item if there is already an item with matching key and cas. ); my $item_put = $iron_cache->put('key' => 'my_item_key', 'item' => $iron_cache_item_put); my $item_put_new_value = $iron_cache->increment('key' => 'my_item_key', 'increment' => 15); my $iron_cache_item_get = $iron_cache->get('key' => 'my_item_key'); my $item_deleted = $iron_cache->delete('key' => 'my_item_key'); # Empty the cache (delete all items inside). Return 1 for success. my $items_cleared_ok = $iron_cache->clear();
An IO::Iron::IronCache::Cache object gives access to a single cache. With it you can do all the normal things one would with a key-value store.
Items are objects of the class IO::Iron::IronCache::Item. It contains the following attributes:
-item - N.B. The item key is not stored in the object.
Cas value changes every time the item value is updated to cache. It can be used to verify that the value has not been changed since the last get operation.
$iron_cache_item_key = 'my_item_key'; my $iron_cache_item_put_1 = IO::Iron::IronCache::Item->new( 'value' => "10", 'expires_in' => 60, # Expires in 60 seconds. 'replace' => 1, ); # Or my $iron_cache_item_put_2 = IO::Iron::IronCache::Item->new( 'value' => "10", 'expires_in' => 60, # Expires in 60 seconds. 'add' => 1, );
IO::Iron::IronCache::Cache objects are created by the client (object of IO::Iron::IronCache::Client) or they can be created by the user. If an item is put to a cache which doesn't exist yet, IronCache creates a new cache automatically.
While it is possible to create a cache object from IO::Iron::IronCache::Cache, user should not normally do this. When the cache object is created by the Client, it gets the Client's REST connection parameters. Otherwise these will need to be set manually.
With an IO::Iron::IronCache::Cache object you can put items to the cache, or get existing items from it.
Get cache id. Not really needed for anything. Just internal reference for Iron Cache.
my $cache_id = $iron_cache->id();
Get cache name.
my $cache_name = $iron_cache->name();
Put an item into the cache. Returns 1 if successful.
my $item_put = $iron_cache->put('key' => $iron_cache_item_key, 'item' => $iron_cache_item_put);
If the item is an integer value, you can simply increment it by another value. If the value is negative, the value in the cache will be decreased. Returns the new value.
my $item_put_new_value = $iron_cache->increment('key' => $iron_cache_item_key, 'increment' => 15);
Get an item from the cache by its name. Returns an object of the class IO::Iron::IronCache::Item if successful.
my $iron_cache_item_get = $iron_cache->get('key' => $iron_cache_item_key);
Delete an item in the cache by its name. Returns 1 if successful.
my $item_deleted_ok = $iron_cache->delete('key' => $iron_cache_item_key);
Clear the cache (delete all items inside). Return 1 for success.
my $items_cleared_ok = $iron_cache->clear();
Please see IO::Iron for documentation on exceptions.
Please see IO::Iron for documentation on policies (limitations to names).
Creator function.
Return objects of class IO::Iron::IronCache::Cache representing all the caches within this project.
Return a IO::Iron::IronCache::Cache object representing a particular key-value cache. The cache object is linked to the creating IO::Iron::IronCache::Client object.
Return a IO::Iron::IronCache::Cache object representing a particular message cache. This call doesn't actually access IronCache API because, if an item is put to a cache which doesn't exist yet, IronCache creates a new cache automatically. create_cache only creates a new IO::Iron::IronCache::Cache object which is linked to its creator IO::Iron::IronCache::Client object.
Delete an IronCache cache.
Mikko Koivunalho, <mikko.koivunalho at iki.fi>
<mikko.koivunalho at iki.fi>
Please report any bugs or feature requests to bug-io-iron at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=IO-Iron. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-io-iron at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc IO::Iron::IronCache::Client
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=IO-Iron
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/IO-Iron
CPAN Ratings
http://cpanratings.perl.org/d/IO-Iron
Search CPAN
http://search.cpan.org/dist/IO-Iron/
Copyright 2013 Mikko Koivunalho.
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:
http://www.perlfoundation.org/artistic_license_2_0
Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.
If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.
This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.
This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
To install IO::Iron, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IO::Iron
CPAN shell
perl -MCPAN -e shell install IO::Iron
For more information on module installation, please visit the detailed CPAN module installation guide.