9 # value -- if defined, loaded. value in range [0,100] (inclusive)
12 my ($class, $knobname) = @_;
13 return $singleton{$knobname} ||= LJ
::Knob
->new($knobname);
17 my ($class, $knobname) = @_;
21 return bless $self, $class;
26 return "knob:$self->{name}";
30 my ($self, $val) = @_;
33 my $memkey = $self->memkey;
34 LJ
::MemCache
::set
($memkey, $val);
35 my $dbh = LJ
::get_db_writer
();
36 $dbh->do("REPLACE INTO knob (knobname, val) VALUES (?, ?)", undef,
39 # broadcast to other apache nodes to change
40 $self->{value
} = $val;
47 return $self->{value
} if defined $self->{value
};
48 my $name = $self->{name
};
50 my $memkey = $self->memkey;
51 my $rv = LJ
::MemCache
::get
($memkey);
53 return $self->{value
} = $rv;
56 my $dbh = LJ
::get_db_writer
();
57 $rv = $dbh->selectrow_array("SELECT val FROM knob WHERE knobname=?", undef, $name) + 0;
58 LJ
::MemCache
::add
($memkey, $rv);
59 return $self->{value
} = $rv;
63 my ($self, $checkon) = @_;
64 my $rand = (127 & int(String
::CRC32
::crc32
($checkon))); # [0 .. 127]
65 my $val = int(127 * $self->value / 100); # [0 .. 127]