#include <opensrf/osrf_cache.h>
+#define MAX_KEY_LEN 250
+
static struct memcached_st* _osrfCache = NULL;
static time_t _osrfCacheMaxSeconds = -1;
static char* _clean_key( const char* );
char* clean_key = (char*)strdup(key);
char* d = clean_key;
char* s = clean_key;
- do while(isspace(*s)) s++; while(*d++ = *s++);
+ do while(isspace(*s) || iscntrl(*s)) s++; while(*d++ = *s++);
+ if (strlen(clean_key) > MAX_KEY_LEN) {
+ char *hashed = md5sum(clean_key);
+ clean_key[0] = '\0';
+ strncat(clean_key, "shortened_", 11);
+ strncat(clean_key, hashed, MAX_KEY_LEN);
+ free(hashed);
+ }
return clean_key;
}
use strict; use warnings;
use base qw/OpenSRF/;
use Cache::Memcached;
+use Digest::MD5 qw(md5_hex);
use OpenSRF::Utils::Logger qw/:level/;
use OpenSRF::Utils::Config;
use OpenSRF::Utils::SettingsClient;
my $key = shift;
$key =~ s{(\p{Cntrl}|\s)}{}g;
+ if (length($key) > 250) { # max length of memcahed key
+ $key = 'shortened_' . md5_hex($key);
+ }
return $key;
}