GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Catalyst::Model::Memcached(3) User Contributed Perl Documentation Catalyst::Model::Memcached(3)

Catalyst::Model::Memcached - Wrapper for memcached imitating Catalyst models

  package MyCatalyst::Model::Token;

  use Moose;
  use namespace::autoclean;

  BEGIN { extends 'Catalyst::Model::Memcached' };

  __PACKAGE__->config( args => { servers => [ '127.0.0.1:11211' ], namespace => 'db' } );
  # Alternatively, this could be specified through config file

  __PACKAGE__->set_primary_key( qw/token/ );
  __PACKAGE__->set_ttl( 300 );

  sub BUILD {
    my $self = shift;
    $self->{__once_initialized_object} = Object->new;
    return $self;
  }

  sub create {
    my ($self, $hash) = @_;
    $hash->{token} = $self->{__once_initialized_object}->create_id();
    return $self->SUPER::create($hash)
  }

  1;

Simple Model for Catalyst for storing data in memcached

Warning Module requires perl >= 5.10 and Catalyst >= 5.8 !

One subclass of model handle one set of primary_key and ttl params. You can think of it as one table in regular DB.

In case you want to use memcached to store different entities through this model, you can configure it like this in config file:

  Model:
    Cached:
      class: MyApp::Store::Cached
      config:
        args:
          servers:
            - 127.0.0.1:11211
          namespace: 'db.'
        ttl: 86400

Assuming your model class is named MyApp::Model::Cached, your memcached server is started on localhost on port 11211. With this configuration all classes MyApp::Store::Cached::* will be loaded with same memcached configuration and default ttl of 86400.

Primary key could be the same in different classes - to avoid clashes keys that are stored in memcached are constructed like 'global_namespace.last_part_of_module_name.primary_key'.

create( hashref )
  $c->model( 'Cached::Token' )->create( 
    { token => 'aaaa', signature => 'abcd' } 
  );
    

Creates record in memcached with key = "primary_key", data = "hashref", expire = "ttl". "hashref" must contains "primary_key".

search( hashref )
  $c->model( 'Cached::Token' )->search( { token => 'aaaa' } );
    

Searches data in memcached by "primary_key" key and returns memcached answer. "hashref" must contains "primary_key".

find( hashref )
The same as search.
find_or_new( hashref )
Calls find, if nothing found - calls create.
delete( hashref )
Delete record with "primary_key".

    Denis Pokataev
    CPAN ID: CATONE
    Sponsored by Openstat.com
    catone@cpan.org

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

Catalyst, Cache::Memcached::Fast, perl(1).
2010-03-23 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.