1. What is the maximum length of the key value ?
The maximum length of the memcached key is one character .
Note 250 is a limitation within the memcached server-side (can be modified)
If you are using a client that supports "key prefixes" or similar features, then the maximum length of key (prefix + original key) can be more than 250 characters.
We recommend using shorter keys because you can save memory and bandwidth.
Key as long as not repeating on the line, if too big waste memory.
2.key cannot have spaces and control characters
The key must not include control characters or whitespace.
- the Item the expiration time limit ?
The expiration time is maximum .
If you do not pay attention to this detail, the Expiration time setting is greater than 30 days, the value will not be set into the cache
- the maximum number of individuals that can be stored item?
1MB
If your data is larger than 1MB, consider compressing or splitting the client into multiple keys.
Code support:
If you use the Spy
Net.spy.memcached.util.StringUtils.validateKey (String)
This method is used to verify that the key
Where code:
Java code
- public static void Validatekey (String key) {
- byte[] keybytes = keyutil.getkeybytes (key);
- if (Keybytes.length > Memcachedclientif.max_key_length) {
- throw new IllegalArgumentException ("Key is too long (MaxLen ="
- + Memcachedclientif.max_key_length + ")");
- }
- if (Keybytes.length = = 0) {
- throw New IllegalArgumentException (
- "Key must contain at least one character.");
- }
- Validate the key
- for (byte b:keybytes) {
- if (b = = ' | | b = = ' \ n ' | | b = = ' \ r ' | | b = = 0) {
- throw New IllegalArgumentException (
- "Key contains invalid characters:" "+ Key +" "");
- }
- }
- }
As you can see, the maximum length is 250, the key of length 0 is not allowed,
If there is a space \ r such a control symbol is not allowed
"Flying the Moon" memcached four important notes (key length, space limit, maximum item)