NAME
Data::Fallback::Daemon - a daemon for Data::Fallback
DESCRIPTION
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.
TYPICAL USAGE
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.
EXAMPLE
#!/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({
# 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(),
});
my $db1_dsn = ['dbi:mysql:CHANGE TO YOUR DATABASE', 'CHANGE TO YOUR USER', 'CHANGE TO YOUR PASSWORD'];
my $db2_dsn = ['dbi:Pg:dbname=CHANGE TO YOUR DATABASE', 'CHANGE TO YOUR USER', 'CHANGE TO YOUR PASSWORD'];
# loaded_list is a hash ref of all the lists you want to have the daemon maintain
# the hash keys two_dbs, second_test are how the lists are referenced
$self->{fallback}{loaded_list} = {
db_to_conf => [
{
content => '/tmp/fallback/$primary_key',
package => 'ConfFile',
accept_update => 'group',
},
{
db => $db1_dsn,
content => 'SELECT foo FROM foo WHERE id = ?',
package => 'DBI',
},
],
two_dbs => [
{
db => $db1_dsn,
content => 'SELECT foo FROM foo WHERE id = ?',
package => 'DBI',
},
{
db => $db2_dsn,
content => 'SELECT foo FROM foo WHERE id = ?',
package => 'DBI',
},
],
};
# all set up, just need to run
$self->run();
1;