Skip to content

Commit

Permalink
fix: use variable in Cache.pm to store memcached max object size
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael0202 committed Aug 8, 2023
1 parent 09a1814 commit 908c6b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/ProductOpener/Cache.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ BEGIN {
use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS);
@EXPORT_OK = qw(
$memd
$max_memcached_object_size
&generate_cache_key
); # symbols to export on request
%EXPORT_TAGS = (all => [@EXPORT_OK]);
Expand All @@ -52,14 +53,17 @@ $memd = Cache::Memcached::Fast->new(
}
);

# Maximum object size that we can store in memcached
$max_memcached_object_size = 1048576;

my $json = JSON->new->utf8->allow_nonref->canonical;

=head1 FUNCTIONS
=head2 generate_cache_key($name, $context_ref)
Generate a key to use for caching, that depends on the content of the $context_ref object.
The key is prependend by the name of the variable we want to store, so that we can set multiple variables for the same context
The key is prepended by the name of the variable we want to store, so that we can set multiple variables for the same context
(e.g. a count of search results + the search results themselves)
=head3 Arguments
Expand Down
4 changes: 2 additions & 2 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1374,8 +1374,8 @@ sub set_cache_results ($key, $results) {
$log->debug("Setting value for MongoDB query key", {key => $key}) if $log->is_debug();
my $result_size = total_size($results);

# memcached max object size is 1 048 576 bytes
if ($result_size >= 1048576) {
# $max_memcached_object_size is defined is Cache.pm
if ($result_size >= $max_memcached_object_size) {
$mongodb_log->info(
"set_cache_results - skipping - setting value - key: $key (total_size: $result_size > max size)");
return;
Expand Down

0 comments on commit 908c6b4

Please sign in to comment.