NAME
Plack::Middleware::Throttle::Lite::Backend::Abstract - Base class for Throttle::Lite backends
VERSION
version 0.05
DESCRIPTION
This class is provided as a base class for each storage backend. Any backend must inherit from it and provide a set of methods described below.
ABSTRACT METHODS
init
Method invoked after object created. Might be used for initialize connections, setting up values in accessors (see "mk_attrs") and so on.
reqs_done
This one should return total proceeded requests for current key (available via method "cache_key"). If no requests done it should return 0.
increment
This method should increment total proceeded requests by one for current key.
METHODS
mk_attrs
Allows to create a list of attributes (accessors) in the backend package. Basic usage is
package My::Backend::Foo;
use parent 'Plack::Middleware::Throttle::Lite::Backend::Abstract';
__PACKAGE__->mk_attrs(qw(foo bar baz));
Warning! You should be careful in picking attributes' names.
cache_key
Unique requester's identifier. Used to store number of requests. Basically it's a string contains
throttle:$REMOTE_ADDR:$REMOTE_USER:$INTERVAL
where
- $REMOTE_ADDR
-
A value of the $ENV{REMOTE_ADDR} (e.g. 127.0.0.1).
- $REMOTE_USER
-
A value of the $ENV{REMOTE_USER}. If this environment variable is not set, value nobody will be used.
- $INTERVAL
-
This value depends on limits used and builds on server's local time. For
per hour
limits it's like YYYYMMDDHH, forper day
limits - YYYYMMDD. Y, M, D, H symbols mean part of current time: YYYY - year, MM - month, DD - day and HH - hour.
Typical values of the cache_key
throttle:127.0.0.1:nobody:2013032006
throttle:10.90.90.90:chim:20130320
expire_in
Time (in seconds) formatted according to given limits of requests after which limits will be reset.
reqs_max
Returns maximum available requests.
requester_id
Returns a part of client indentifier. A value will changing via the main module Plack::Middleware::Throttle::Lite. In common, it's looks like
throttle:$REMOTE_ADDR:$REMOTE_USER
See "cache_key" for details about $REMOTE_ADDR and $REMOTE_USER.
settings
Returns some configuration parameters for given limits of requests.
units
Returns measuring units for given limits of requests.
ymdh
Returns value of current date and time according to given limits.
BACKENDS OVERVIEW
Each backend can be implemented in Plack::Middleware::Throttle::Lite::Backend namespace or in your preferred namespace like My::OwnSpace. In this case you should provide full module name prepended with +
(plus) sign in middleware's options.
enable 'Throttle::Lite',
backend => '+My::OwnSpace::MyBackend';
or (with options)
enable 'Throttle::Lite',
backend => [ '+My::OwnSpace::MyBackend' => { foo => 'bar', baz => 1 } ];
At the moment known the following storage backends:
Plack::Middleware::Throttle::Lite::Backend::Simple
Very simple (in-memory) storage backend. Shipped with this distribution. All data holds in memory. See details Plack::Middleware::Throttle::Lite::Backend::Simple.
Plack::Middleware::Throttle::Lite::Backend::Redis
Redis-driven storage backend. Take care about memory consumption, has re-connect feature and can use tcp or unix-socket connection to the redis-server. See details Plack::Middleware::Throttle::Lite::Backend::Redis.
Plack::Middleware::Throttle::Lite::Backend::Memcached
Memcached-driven storage backend. See details Plack::Middleware::Throttle::Lite::Backend::Memcached.
BUGS
Please report any bugs or feature requests through the web interface at https://github.com/Wu-Wu/Plack-Middleware-Throttle-Lite/issues
SEE ALSO
Plack::Middleware::Throttle::Lite
Plack::Middleware::Throttle::Lite::Backend::Simple
AUTHOR
Anton Gerasimov <chim@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Anton Gerasimov.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.