cache'owanie danych w php
TRANSCRIPT
![Page 1: Cache'owanie danych w PHP](https://reader030.vdocument.in/reader030/viewer/2022032616/55a68d9c1a28abb27d8b4737/html5/thumbnails/1.jpg)
Patryk Jar
![Page 2: Cache'owanie danych w PHP](https://reader030.vdocument.in/reader030/viewer/2022032616/55a68d9c1a28abb27d8b4737/html5/thumbnails/2.jpg)
Agenda
� Definition � Methodologies � Solutions � Tips � What else can I do on my page?
![Page 3: Cache'owanie danych w PHP](https://reader030.vdocument.in/reader030/viewer/2022032616/55a68d9c1a28abb27d8b4737/html5/thumbnails/3.jpg)
Definition
Cache – a collection of data duplicating or ig ina l va lues s tored e lsewhere on a computer
wikipedia.org
![Page 4: Cache'owanie danych w PHP](https://reader030.vdocument.in/reader030/viewer/2022032616/55a68d9c1a28abb27d8b4737/html5/thumbnails/4.jpg)
Methodologies
� Whole page (use proxy) � Partial page � Database queries (example) � Re-usable objects (example)
![Page 5: Cache'owanie danych w PHP](https://reader030.vdocument.in/reader030/viewer/2022032616/55a68d9c1a28abb27d8b4737/html5/thumbnails/5.jpg)
Caching static pages
![Page 6: Cache'owanie danych w PHP](https://reader030.vdocument.in/reader030/viewer/2022032616/55a68d9c1a28abb27d8b4737/html5/thumbnails/6.jpg)
Caching database queries 1. function cachedSingleRowQuery(!2. $query, array $bind, $expiry, PDO $db, Memcached $cache!3. ) {!4. $key = 'query' . md5($query . implode(',', $bind));!5. $obj = $cache->get($key);!6. if ( ! $obj ) {!7. $result = $db->prepare($query)->execute($bind);!8. $obj = $result->fetchObject();!9. $cache->set($key, $obj, $expiry);!10. }!11. !12. return $obj;!13. }!
![Page 7: Cache'owanie danych w PHP](https://reader030.vdocument.in/reader030/viewer/2022032616/55a68d9c1a28abb27d8b4737/html5/thumbnails/7.jpg)
Cache Invalidation Strategy
� Time expiration � Update invalidation (DVSA Project ;) ) � Pre-generation (e.g. Facebook)
![Page 8: Cache'owanie danych w PHP](https://reader030.vdocument.in/reader030/viewer/2022032616/55a68d9c1a28abb27d8b4737/html5/thumbnails/8.jpg)
Application – no cache
…
…
HTTP requests
![Page 9: Cache'owanie danych w PHP](https://reader030.vdocument.in/reader030/viewer/2022032616/55a68d9c1a28abb27d8b4737/html5/thumbnails/9.jpg)
Application – cached data
… …
cache (e.g. session)
DataStore Interface
REST API (HTTP)
![Page 10: Cache'owanie danych w PHP](https://reader030.vdocument.in/reader030/viewer/2022032616/55a68d9c1a28abb27d8b4737/html5/thumbnails/10.jpg)
Tester Application - example 1. function get($uuid)!2. {!3. $application = getApplicationFromSession();!4.!5. if (null === $application) {!6. $data = api->getTesterApplication($uuid);!7. $application = new TesterApplication($data);!8. storeInSession($application);!9. }!10. !11. return $application ;!12. }!
![Page 11: Cache'owanie danych w PHP](https://reader030.vdocument.in/reader030/viewer/2022032616/55a68d9c1a28abb27d8b4737/html5/thumbnails/11.jpg)
Solutions
� APC � http://uk1.php.net/apc/
� Memcached � http://memcached.org/
� HTML5 API (in web browser): � localStorage � sessionStorage
![Page 12: Cache'owanie danych w PHP](https://reader030.vdocument.in/reader030/viewer/2022032616/55a68d9c1a28abb27d8b4737/html5/thumbnails/12.jpg)
Tips
![Page 13: Cache'owanie danych w PHP](https://reader030.vdocument.in/reader030/viewer/2022032616/55a68d9c1a28abb27d8b4737/html5/thumbnails/13.jpg)
![Page 14: Cache'owanie danych w PHP](https://reader030.vdocument.in/reader030/viewer/2022032616/55a68d9c1a28abb27d8b4737/html5/thumbnails/14.jpg)
![Page 15: Cache'owanie danych w PHP](https://reader030.vdocument.in/reader030/viewer/2022032616/55a68d9c1a28abb27d8b4737/html5/thumbnails/15.jpg)
What else can I do on my page?
� Externalize re-usable JS and CSS � Merge and compress CSS files � Merge and compress JavaScript files � Use CSS Sprites � Use Content Delivery Network
� https://developers.google.com/speed/libraries/
![Page 16: Cache'owanie danych w PHP](https://reader030.vdocument.in/reader030/viewer/2022032616/55a68d9c1a28abb27d8b4737/html5/thumbnails/16.jpg)
Thank you
� Qs?