Plack::Middleware::Throttle::Lite::Backend::Abstract - Base class for Throttle::Lite backends
version 0.05
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.
Method invoked after object created. Might be used for initialize connections, setting up values in accessors (see "mk_attrs") and so on.
This one should return total proceeded requests for current key (available via method "cache_key"). If no requests done it should return 0.
This method should increment total proceeded requests by one for current key.
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.
Unique requester's identifier. Used to store number of requests. Basically it's a string contains
throttle:$REMOTE_ADDR:$REMOTE_USER:$INTERVAL
where
A value of the $ENV{REMOTE_ADDR} (e.g. 127.0.0.1).
A value of the $ENV{REMOTE_USER}. If this environment variable is not set, value nobody will be used.
This value depends on limits used and builds on server's local time. For per hour limits it's like YYYYMMDDHH, for per day limits - YYYYMMDD. Y, M, D, H symbols mean part of current time: YYYY - year, MM - month, DD - day and HH - hour.
per hour
per day
Typical values of the cache_key
throttle:127.0.0.1:nobody:2013032006 throttle:10.90.90.90:chim:20130320
Time (in seconds) formatted according to given limits of requests after which limits will be reset.
Returns maximum available requests.
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.
Returns some configuration parameters for given limits of requests.
Returns measuring units for given limits of requests.
Returns value of current date and time according to given limits.
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:
Very simple (in-memory) storage backend. Shipped with this distribution. All data holds in memory. See details Plack::Middleware::Throttle::Lite::Backend::Simple.
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.
Memcached-driven storage backend. See details Plack::Middleware::Throttle::Lite::Backend::Memcached.
Please report any bugs or feature requests through the web interface at https://github.com/Wu-Wu/Plack-Middleware-Throttle-Lite/issues
Plack::Middleware::Throttle::Lite
Plack::Middleware::Throttle::Lite::Backend::Simple
Anton Gerasimov <chim@cpan.org>
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.
To install Plack::Middleware::Throttle::Lite, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::Middleware::Throttle::Lite
CPAN shell
perl -MCPAN -e shell install Plack::Middleware::Throttle::Lite
For more information on module installation, please visit the detailed CPAN module installation guide.