Developing a
memcached
Application
1359
•
get(key)
: Retrieves information from the cache. Returns the value associated with the key if the
specified key exists. Returns
NULL
,
nil
,
undefined
, or the closest equivalent in the corresponding
language, if the specified key does not exist.
•
set(key, value [, expiry])
: Sets the item associated with a key in the cache to the specified
value. Note that this either updates an existing item if the key already exists, or adds a new key/value
pair if the key doesn't exist. If the expiry time is specified, then the item expires (and is deleted) when
the expiry time is reached. The time is specified in seconds, and is taken as a relative time if the
value is less than 30 days (30*24*60*60), or an absolute time (epoch) if larger than this value.
•
add(key, value [, expiry])
: Adds the key and associated value to the cache, if the specified
key does not already exist.
•
replace(key, value [, expiry])
: Replaces the item associated with the specified
key
, only
if the key already exists. The new value is given by the
value
parameter.
•
delete(key [, time])
: Deletes the
key
and its associated item from the cache. If you supply a
time
, then adding another item with the specified
key
is blocked for the specified period.
•
incr(key [, value])
: Increments the item associated with the
key
by one or the optional
value
.
•
decr(key [, value])
: Decrements the item associated with the
key
by one or the optional
value
.
•
flush_all
: Invalidates (or expires) all the current items in the cache. Technically they still exist
(they are not deleted), but they are silently destroyed the next time you try to access them.
In all implementations, most or all of these functions are duplicated through the corresponding native
language interface.
When practical, use
memcached
to store full items, rather than caching a single column value from the
database. For example, when displaying a record about an object (invoice, user history, or blog post),
load all the data for the associated entry from the database, and compile it into the internal structure
that would normally be required by the application. Save the complete object in the cache.
Complex data structures cannot be stored directly. Most interfaces serialize the data for you, that is,
put it in a textual form that can reconstruct the original pointers and nesting. Perl uses
Storable
, PHP
uses
serialize
, Python uses
cPickle
(or
Pickle
) and Java uses the
Serializable
interface.
In most cases, the serialization interface used is customizable. To share data stored in
memcached
instances between different language interfaces, consider using a common serialization solution such
as JSON (Javascript Object Notation).
15.6.3.2. Using
memcached
as a MySQL Caching Layer
When using
memcached
to cache MySQL data, your application must retrieve data from the database
and load the appropriate key-value pairs into the cache. Then, subsequent lookups can be done
directly from the cache.
Because MySQL has its own in-memory caching mechanisms for queried data, such as the
InnoDB
buffer pool
and the MySQL query cache, look for opportunities beyond loading individual column values
or rows into the cache. Prefer to cache composite values, such as those retrieved from multiple tables
through a join query, or result sets assembled from multiple rows.
Caution
Limit the information in the cache to non-sensitive data, because there is no
security required to access or update the information within a
memcached
instance. Anybody with access to the machine has the ability to read, view
and potentially update the information. To keep the data secure, encrypt the
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...