Subject: | Do not try to store in cache too big values |
memcached does not accept values bigger than 1mb. Moreover, it's
commonly not very useful to cache big values -- they are probably rare.
We here at Rambler have an option "too_big_threshold" in
Cache::Memcached which sets the size in bytes after which no storing is
even attempted. It would be nice to have the same option in Fast. The
change is very simple and I thought it would be more practical for the
author to implement it :) And I missed my XS-fu classes, too :(
Such logic cannot be elegantly implemented on the application side
because serialization is done inside Cache::Memcached.
I attach my Perl patch to the latest BRADFITZ's Cache::Memcached, it
could be useful.
Subject: | toobig.patch |
--- Memcached.pm.orig 2007-07-17 22:40:23.000000000 +0400
+++ Memcached.pm 2008-05-02 21:43:22.000000000 +0400
@@ -25,6 +25,7 @@
bucketcount _single_sock _stime
connect_timeout cb_connect_fail
parser_class
+ too_big_threshold
};
# flag definitions
@@ -76,6 +77,7 @@
$self->{'stat_callback'} = $args->{'stat_callback'} || undef;
$self->{'readonly'} = $args->{'readonly'};
$self->{'parser_class'} = $args->{'parser_class'} || $parser_class;
+ $self->{'too_big_threshold'} = $args->{'too_big_threshold'};
# TODO: undocumented
$self->{'connect_timeout'} = $args->{'connect_timeout'} || 0.25;
@@ -460,6 +462,10 @@
my $len = length($val);
+ if ($self->{'too_big_threshold'} && $len >= $self->{'too_big_threshold'}) {
+ return 1; # positive NOP
+ }
+
if ($self->{'compress_threshold'} && $HAVE_ZLIB && $self->{'compress_enable'} &&
$len >= $self->{'compress_threshold'}) {
@@ -959,6 +965,10 @@
Values larger than this threshold will be compressed by C<set> and
decompressed by C<get>.
+Use C<too_big_threshold> to set the upper limit on size of cached data
+items. Values larger than this threshold won't be sent over the
+network. It's no use to send >1MB values anyway, they are not stored.
+
Use C<no_rehash> to disable finding a new memcached server when one
goes down. Your application may or may not need this, depending on
your expirations and key usage.
@@ -1002,6 +1012,10 @@
Sets the compression threshold. See C<new> constructor for more information.
+=item C<set_too_big_threshold>
+
+Sets the overall size threshold. See C<new> constructor for more information.
+
=item C<enable_compress>
Temporarily enable or disable compression. Has no effect if C<compress_threshold>