Professional Documents
Culture Documents
Hi, Im Ben.
benramsey.com
@ramsey
joind.in/1599
What is a cache?
Types of caches
File system
Database
Shared memory
RAM disk
Object cache (memcached and APC)
Opcode cache (APC)
Memcached
What is memcached?
Facebook
Digg
Youtube
Wikipedia
Us (Moontoast)
Many others...
Memcached principles
Memcached principles
memcached
www
www
memcached
memcached
www
memcached
www
www
memcached
memcached
www
Storage commands:
$book = $memcache->get('0764596349');
if ($book === false)
{
if ($memcache->getResultCode()
== Memcached::RES_NOTFOUND)
{
$book = Book::getByIsbn('0764596349');
$memcache->set($book->getCacheKey(), $book);
}
}
Memcached limits
pecl/memcached
pecl/memcached basics
Memcached::OPT_COMPRESSION
Memcached::OPT_DISTRIBUTION
Memcached::OPT_LIBKETAMA_COMPATIBLE
Memcached::OPT_BINARY_PROTOCOL
Memcached::OPT_NO_BLOCK
Memcached methods
add()
addServer()
append()
cas()
decrement()
delete()
get()
getMulti()
getResultCode()
getResultMessage()
getServerList()
getStats()
increment()
prepend()
replace()
set()
setMulti()
... and more!
Alternative PHP
Cache (APC)
apc
www
www
apc
apc
www
What is APC?
Opcode cache
Provides object caching (also referred to
in places as APC user variables)
example.com/
APC
index.php
public/index.php
library/Zend/Application.php
library/Zend/Loader/Autoloader.php
library/Zend/Loader.php
library/Zend/Config/Ini.php
library/Zend/Config.php
application/Bootstrap.php
library/Zend/Application/Bootstrap/Bootstrap.php
library/Zend/Application/Bootstrap/BootstrapAbstract.php
library/Zend/Application/Bootstrap/Bootstrapper.php
library/Zend/Application/Bootstrap/
ResourceBootstrapper.php
library/Zend/Application/Module/Autoloader.php
library/Zend/Loader/Autoloader/Resource.php
library/Zend/Loader/Autoloader/Interface.php
library/Zend/Loader/PluginLoader.php
... 48 more files ...
example.com/
APC
index.php
public/index.php
library/Zend/Application.php
library/Zend/Loader/Autoloader.php
library/Zend/Loader.php
library/Zend/Config/Ini.php
library/Zend/Config.php
application/Bootstrap.php
library/Zend/Application/Bootstrap/Bootstrap.php
library/Zend/Application/Bootstrap/BootstrapAbstract.php
library/Zend/Application/Bootstrap/Bootstrapper.php
library/Zend/Application/Bootstrap/
ResourceBootstrapper.php
library/Zend/Application/Module/Autoloader.php
library/Zend/Loader/Autoloader/Resource.php
library/Zend/Loader/Autoloader/Interface.php
library/Zend/Loader/PluginLoader.php
... 48 more files ...
/welcome
Magic!
en.php
background
process
language
key
translation
en
HELLO
Hello
fr
HELLO
Bonjour
es
HELLO
Hola
de
HELLO
Hallo
nl
HELLO
Hallo
fi
HELLO
Hei
ga
HELLO
Dia duit
pt
HELLO
Ol
...
...
...
...
...
...
...
...
...
data
base
Even better:
store the array to
APC with apc_store()!
APC functions
apc_cache_info()
apc_clear_cache()
apc_sma_info()
apc_store()
apc_fetch()
apc_delete()
apc_delete_file()
apc_compile_file()
apc_define_constants()
apc_load_constants()
apc_add()
apc_inc()
apc_dec()
apc_cas()
apc_bin_dump()
apc_bin_load()
apc_bin_dumpfile()
apc_bin_loadfile()
Advanced APC
apc_compile_file()
apc_bin_dump()
apc_bin_load()
apc_bin_dumpfile()
apc_bin_loadfile()
Memcached
vs. APC
Application settings
Configuration
Data that is the same for each user
Requests are guaranteed to go to the
same machine (i.e. sticky sessions)
Questions?
Thank you!
Ben Ramsey
benramsey.com
@ramsey
joind.in/1599