<s>
Memcached	B-Application
(	O
pronounced	O
variously	O
mem-cash-dee	O
or	O
mem-cashed	O
)	O
is	O
a	O
general-purpose	O
distributed	O
memory-caching	B-General_Concept
system	O
.	O
</s>
<s>
It	O
is	O
often	O
used	O
to	O
speed	O
up	O
dynamic	O
database-driven	O
websites	O
by	O
caching	B-General_Concept
data	O
and	O
objects	O
in	O
RAM	B-Architecture
to	O
reduce	O
the	O
number	O
of	O
times	O
an	O
external	O
data	O
source	O
(	O
such	O
as	O
a	O
database	O
or	O
API	B-Application
)	O
must	O
be	O
read	O
.	O
</s>
<s>
Memcached	B-Application
is	O
free	B-License
and	I-License
open-source	I-License
software	I-License
,	O
licensed	O
under	O
the	O
Revised	O
BSD	O
license	O
.	O
</s>
<s>
Memcached	B-Application
runs	O
on	O
Unix-like	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
(	O
Linux	B-Application
and	O
macOS	B-Application
)	O
and	O
on	O
Microsoft	B-Application
Windows	I-Application
.	O
</s>
<s>
It	O
depends	O
on	O
the	O
libevent	B-Language
library	O
.	O
</s>
<s>
Memcached	B-Application
's	O
APIs	B-Application
provide	O
a	O
very	O
large	O
hash	B-Algorithm
table	I-Algorithm
distributed	O
across	O
multiple	O
machines	O
.	O
</s>
<s>
When	O
the	O
table	O
is	O
full	O
,	O
subsequent	O
inserts	O
cause	O
older	O
data	O
to	O
be	O
purged	O
in	O
least	B-General_Concept
recently	I-General_Concept
used	I-General_Concept
(	O
LRU	O
)	O
order	O
.	O
</s>
<s>
Applications	O
using	O
Memcached	B-Application
typically	O
layer	O
requests	O
and	O
additions	O
into	O
RAM	B-Architecture
before	O
falling	O
back	O
on	O
a	O
slower	O
backing	B-General_Concept
store	I-General_Concept
,	O
such	O
as	O
a	O
database	O
.	O
</s>
<s>
Memcached	B-Application
has	O
no	O
internal	O
mechanism	O
to	O
track	O
misses	O
which	O
may	O
happen	O
.	O
</s>
<s>
Memcached	B-Application
was	O
first	O
developed	O
by	O
Brad	O
Fitzpatrick	O
for	O
his	O
website	O
LiveJournal	B-Application
,	O
on	O
May	O
22	O
,	O
2003	O
.	O
</s>
<s>
It	O
was	O
originally	O
written	O
in	O
Perl	B-Language
,	O
then	O
later	O
rewritten	O
in	O
C	B-Language
by	O
Anatoly	O
Vorobey	O
,	O
then	O
employed	O
by	O
LiveJournal	B-Application
.	O
</s>
<s>
Memcached	B-Application
is	O
now	O
used	O
by	O
many	O
other	O
systems	O
,	O
including	O
YouTube	B-General_Concept
,	O
Reddit	B-Application
,	O
Facebook	B-Application
,	O
Pinterest	B-Application
,	O
Twitter	B-Application
,	O
Wikipedia	O
,	O
and	O
Method	O
Studios	O
.	O
</s>
<s>
Google	B-Application
App	I-Application
Engine	I-Application
,	O
Google	B-General_Concept
Cloud	I-General_Concept
Platform	I-General_Concept
,	O
Microsoft	B-Application
Azure	I-Application
,	O
IBM	B-General_Concept
Bluemix	I-General_Concept
and	O
Amazon	B-Application
Web	I-Application
Services	I-Application
also	O
offer	O
a	O
Memcached	B-Application
service	O
through	O
an	O
API	B-Application
.	O
</s>
<s>
The	O
system	O
uses	O
a	O
client	B-Operating_System
–	I-Operating_System
server	I-Operating_System
architecture	I-Operating_System
.	O
</s>
<s>
The	O
servers	O
maintain	O
a	O
key	O
–	O
value	O
associative	B-Application
array	I-Application
;	O
the	O
clients	O
populate	O
this	O
array	O
and	O
query	O
it	O
by	O
key	O
.	O
</s>
<s>
Clients	O
use	O
client-side	B-Operating_System
libraries	O
to	O
contact	O
the	O
servers	O
which	O
,	O
by	O
default	O
,	O
expose	O
their	O
service	O
at	O
port	B-Protocol
11211	O
.	O
</s>
<s>
If	O
a	O
client	O
wishes	O
to	O
set	O
or	O
read	O
the	O
value	O
corresponding	O
to	O
a	O
certain	O
key	O
,	O
the	O
client	O
's	O
library	O
first	O
computes	O
a	O
hash	B-Error_Name
of	O
the	O
key	O
to	O
determine	O
which	O
server	O
to	O
use	O
.	O
</s>
<s>
This	O
gives	O
a	O
simple	O
form	O
of	O
sharding	B-General_Concept
and	O
scalable	O
shared-nothing	B-Operating_System
architecture	I-Operating_System
across	O
the	O
servers	O
.	O
</s>
<s>
The	O
server	O
computes	O
a	O
second	O
hash	B-Error_Name
of	O
the	O
key	O
to	O
determine	O
where	O
to	O
store	O
or	O
read	O
the	O
corresponding	O
value	O
.	O
</s>
<s>
The	O
servers	O
keep	O
the	O
values	O
in	O
RAM	B-Architecture
;	O
if	O
a	O
server	O
runs	O
out	O
of	O
RAM	B-Architecture
,	O
it	O
discards	O
the	O
oldest	O
values	O
.	O
</s>
<s>
Therefore	O
,	O
clients	O
must	O
treat	O
Memcached	B-Application
as	O
a	O
transitory	O
cache	B-General_Concept
;	O
they	O
cannot	O
assume	O
that	O
data	O
stored	O
in	O
Memcached	B-Application
is	O
still	O
there	O
when	O
they	O
need	O
it	O
.	O
</s>
<s>
Other	O
databases	O
,	O
such	O
as	O
MemcacheDB	B-Application
,	O
Couchbase	B-Operating_System
Server	I-Operating_System
,	O
provide	O
persistent	O
storage	O
while	O
maintaining	O
Memcached	B-Application
protocol	O
compatibility	O
.	O
</s>
<s>
If	O
all	O
client	O
libraries	O
use	O
the	O
same	O
hashing	B-Error_Name
algorithm	I-Error_Name
to	O
determine	O
servers	O
,	O
then	O
clients	O
can	O
read	O
each	O
other	O
's	O
cached	O
data	O
.	O
</s>
<s>
However	O
,	O
it	O
is	O
possible	O
to	O
use	O
Memcached	B-Application
on	O
a	O
single	O
computer	O
,	O
acting	O
simultaneously	O
as	O
client	O
and	O
server	O
.	O
</s>
<s>
The	O
size	O
of	O
its	O
hash	B-Algorithm
table	I-Algorithm
is	O
often	O
very	O
large	O
.	O
</s>
<s>
Memcached	B-Application
can	O
be	O
equally	O
valuable	O
for	O
situations	O
where	O
either	O
the	O
number	O
of	O
requests	O
for	O
content	O
is	O
high	O
,	O
or	O
the	O
cost	O
of	O
generating	O
a	O
particular	O
piece	O
of	O
content	O
is	O
high	O
.	O
</s>
<s>
Most	O
deployments	O
of	O
Memcached	B-Application
are	O
within	O
trusted	O
networks	O
where	O
clients	O
may	O
freely	O
connect	O
to	O
any	O
server	O
.	O
</s>
<s>
However	O
,	O
sometimes	O
Memcached	B-Application
is	O
deployed	O
in	O
untrusted	O
networks	O
or	O
where	O
administrators	O
want	O
to	O
exercise	O
control	O
over	O
the	O
clients	O
that	O
are	O
connecting	O
.	O
</s>
<s>
For	O
this	O
purpose	O
Memcached	B-Application
can	O
be	O
compiled	O
with	O
optional	O
SASL	O
authentication	O
support	O
.	O
</s>
<s>
A	O
presentation	O
at	O
BlackHat	O
USA	O
2010	O
revealed	O
that	O
a	O
number	O
of	O
large	O
public	O
websites	O
had	O
left	O
Memcached	B-Application
open	O
to	O
inspection	O
,	O
analysis	O
,	O
retrieval	O
,	O
and	O
modification	O
of	O
data	O
.	O
</s>
<s>
Even	O
within	O
a	O
trusted	O
organisation	O
,	O
the	O
flat	O
trust	O
model	O
of	O
memcached	B-Application
may	O
have	O
security	O
implications	O
.	O
</s>
<s>
For	O
efficient	O
simplicity	O
,	O
all	O
Memcached	B-Application
operations	O
are	O
treated	O
equally	O
.	O
</s>
<s>
Clients	O
with	O
a	O
valid	O
need	O
for	O
access	O
to	O
low-security	O
entries	O
within	O
the	O
cache	B-General_Concept
gain	O
access	O
to	O
all	O
entries	O
within	O
the	O
cache	B-General_Concept
,	O
even	O
when	O
these	O
are	O
higher-security	O
and	O
that	O
client	O
has	O
no	O
justifiable	O
need	O
for	O
them	O
.	O
</s>
<s>
If	O
the	O
cache	B-General_Concept
key	O
can	O
be	O
either	O
predicted	O
,	O
guessed	O
or	O
found	O
by	O
exhaustive	O
searching	O
,	O
its	O
cache	B-General_Concept
entry	O
may	O
be	O
retrieved	O
.	O
</s>
<s>
A	O
farm	O
of	O
outward-facing	O
content	O
servers	O
have	O
read	O
access	O
to	O
memcached	B-Application
containing	O
published	O
pages	O
or	O
page	O
components	O
,	O
but	O
no	O
write	O
access	O
.	O
</s>
<s>
Where	O
new	O
content	O
is	O
published	O
(	O
and	O
is	O
not	O
yet	O
in	O
memcached	B-Application
)	O
,	O
a	O
request	O
is	O
instead	O
sent	O
to	O
content	O
generation	O
servers	O
that	O
are	O
not	O
publicly	O
accessible	O
to	O
create	O
the	O
content	O
unit	O
and	O
add	O
it	O
to	O
memcached	B-Application
.	O
</s>
<s>
In	O
February	O
2018	O
,	O
CloudFlare	B-Application
reported	O
that	O
misconfigured	O
memcached	B-Application
servers	O
were	O
used	O
to	O
launch	O
DDoS	O
attacks	O
in	O
large	O
scale	O
.	O
</s>
<s>
The	O
memcached	B-Application
protocol	O
over	O
UDP	O
has	O
a	O
huge	O
amplification	O
factor	O
,	O
of	O
more	O
than	O
51000	O
.	O
</s>
<s>
Victims	O
of	O
the	O
DDoS	O
attacks	O
include	O
GitHub	B-Application
,	O
which	O
was	O
flooded	O
with	O
1.35	O
Tbit/s	O
peak	O
incoming	O
traffic	O
.	O
</s>
<s>
This	O
issue	O
was	O
mitigated	O
in	O
Memcached	B-Application
version	O
1.5.6	O
,	O
which	O
disabled	O
UDP	O
protocol	O
by	O
default	O
.	O
</s>
<s>
Note	O
that	O
all	O
functions	O
described	O
on	O
this	O
page	O
are	O
pseudocode	B-Language
only	O
.	O
</s>
<s>
Memcached	B-Application
calls	O
and	O
programming	O
languages	O
may	O
vary	O
based	O
on	O
the	O
API	B-Application
used	O
.	O
</s>
<s>
Converting	O
database	O
or	O
object	O
creation	O
queries	O
to	O
use	O
Memcached	B-Application
is	O
simple	O
.	O
</s>
<s>
The	O
client	O
would	O
first	O
check	O
whether	O
a	O
Memcached	B-Application
value	O
with	O
the	O
unique	O
key	O
"	O
userrow:userid	O
"	O
exists	O
,	O
where	O
userid	O
is	O
some	O
number	O
.	O
</s>
<s>
If	O
the	O
result	O
does	O
not	O
exist	O
,	O
it	O
would	O
select	O
from	O
the	O
database	O
as	O
usual	O
,	O
and	O
set	O
the	O
unique	O
key	O
using	O
the	O
Memcached	B-Application
API	B-Application
add	O
function	O
call	O
.	O
</s>
<s>
However	O
,	O
if	O
only	O
this	O
API	B-Application
call	O
were	O
modified	O
,	O
the	O
server	O
would	O
end	O
up	O
fetching	O
incorrect	O
data	O
following	O
any	O
database	O
update	O
actions	O
:	O
the	O
Memcached	B-Application
"	O
view	O
"	O
of	O
the	O
data	O
would	O
become	O
out	O
of	O
date	O
.	O
</s>
<s>
Therefore	O
,	O
in	O
addition	O
to	O
creating	O
an	O
"	O
add	O
"	O
call	O
,	O
an	O
update	O
call	O
would	O
also	O
be	O
needed	O
using	O
the	O
Memcached	B-Application
set	O
function	O
.	O
</s>
<s>
An	O
alternative	O
approach	O
would	O
be	O
to	O
invalidate	O
the	O
cache	B-General_Concept
with	O
the	O
Memcached	B-Application
delete	O
function	O
,	O
so	O
that	O
subsequent	O
fetches	O
result	O
in	O
a	O
cache	B-General_Concept
miss	O
.	O
</s>
<s>
Similar	O
action	O
would	O
need	O
to	O
be	O
taken	O
when	O
database	O
records	O
were	O
deleted	O
,	O
to	O
maintain	O
either	O
a	O
correct	O
or	O
incomplete	O
cache	B-General_Concept
.	O
</s>
<s>
An	O
alternate	O
cache-invalidation	O
strategy	O
is	O
to	O
store	O
a	O
random	O
number	O
in	O
an	O
agreed-upon	O
cache	B-General_Concept
entry	O
and	O
to	O
incorporate	O
this	O
number	O
into	O
all	O
keys	O
that	O
are	O
used	O
to	O
store	O
a	O
particular	O
kind	O
of	O
entry	O
.	O
</s>
<s>
MySQL	B-Application
-	O
directly	O
supports	O
the	O
Memcached	B-Application
API	B-Application
as	O
of	O
version	O
5.6	O
.	O
</s>
<s>
Oracle	B-Application
Coherence	I-Application
-	O
directly	O
supports	O
the	O
Memcached	B-Application
API	B-Application
as	O
of	O
version	O
12.1.3	O
.	O
</s>
<s>
Infinispan	B-Language
-	O
directly	O
supports	O
Memcached	B-Application
.	O
</s>
