注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
1. what is caching? A copy of real data with faster access. A cache is a collection of data duplicating original values stored elsewhere or computed earlier, where the original data is expensive to fetch (owing to longer access time) or to compute, compared to the cost of reading the cache.
2. Where are caches used? at hardware level, operating systems, web stack, applications, your own short term vs long term memory, browser cache, DNS cache, CDN, Proxy servers. Application level: full output caching, opcode cache, query cache, storing denormalized results in the database, object cache, storing values in php objects/classes
3. Efficiency of caching: the earlier in the process, the closer to the original request, the faster. Browser cache will be faster than cache on a proxy. But probably also the harder to get it right, the closer to the requester, the more parameters the cache depends on.
4. What to cache on the server-side? Expensive operations, database access, reading files, API calls, Heavy computations, XML, user sessions, user data, homepage data
5. Where to cache on the server-side? Database(computed values, generated htmls), Static files(generated html or serialized php values)
6. Memcached: it's a server, client access over TCP or UDP, servers can run in pools: eg. 3 servers with 64 GB mem each give you a single pool of 192GB storage for caching, servers are independent, clients manage the pool
7. Memcached principles: Fast network access(memcached servers close to other application servers), No persistency(if your server goes down, data in memcached is gone), No redundancy/Fail-over, No replication(Single item in cache lives on one server only), No authentication, 1 key is maximum 1MB, keys are strings of 250 chars, No enumeration of keys, no active clean-up
8."There are only two hard things in Computer Science: cache invalidation and naming things." Phil Karlton
9 Invalidation: 9.1 caching for a certain amount of time, eg. 10 minutes, don't delete caches, thus you can't trust that data coming from cache is correct. This is great for summaries: overview or pages where it's not that big a problem if data is a little bit out of date(search results). 9.2 Store forever and expire on certain events(eg. store user data forever, when user changes any of his preferences, throw cache away )
10. Query caching: queries with JOIN and WHERE statements are harder to cache, so we can do join in PHP
11. Use of Multiget in memcached to reduce access cost. eg. find UID from array: SELECT ... FROM USERS WHERE uid IN (...), for each fetched user, store in cache and return merged cache/db results |