Data::Fallback::Daemon - a daemon for Data::Fallback
Data::Fallback works great at finding data at the fastest place you tell it, but what happens when you keep asking for the same data repeatedly? Well, Data::Fallback::Daemon allow to cache in memory the data, and a simple protocol for retrieving it.
Having one database box and n client boxes doesn't scale too hot for n very large. However, one database box and n client boxes each running their own Data::Fallback::Daemon scales well for large n. So, typical usage in my view is to have local daemons running on each client box.
This example requires DBI and DBD::mysql to be installed on the box. #!/usr/bin/perl -w use strict; use Data::Fallback; use Data::Fallback::Daemon; # first we set up a simple Data::Fallback::Daemon object my $self = Data::Fallback::Daemon->new({ # you can change the port if you like port => '20203', # reverse_lookups can take awhile when you aren't connected to the web, # so I just turn them off for testing purposees reverse_lookups => '', # we need to include a Data::Fallback object fallback => Data::Fallback->new(), }); # this is just a dumb test server that I can't guarantee will be up # generally, db is an array ref of your connection info my $db = ["DBI:mysql:database=fallback;host=spack.net;port=7777", "fallback", ""]; # loaded_list is a hash ref of all the lists you want to have the daemon maintain # the hash key state is how the list is referenced $self->{fallback}{loaded_list} = { state => [ { content => '/tmp/fallback/state_$primary_key', package => 'ConfFile', accept_update => 'group', }, { db => $db, content => 'SELECT * FROM state WHERE id = ?', package => 'DBI', }, ], }; # all set up, just need to run $self->run();
Thanks to Paul Seamons for Net::Server and for helping me set up this simple daemon.
Copyright 2001-2002, Earl J. Cahill. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Address bug reports and comments to: cpan@spack.net.
When sending bug reports, please provide the version of Data::Fallback, the version of Perl, and the name and version of the operating system you are using.
To install CacheHash, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CacheHash
CPAN shell
perl -MCPAN -e shell install CacheHash
For more information on module installation, please visit the detailed CPAN module installation guide.