Last active
August 29, 2015 14:26
-
-
Save Crell/12f8331dda65ea303ddd to your computer and use it in GitHub Desktop.
Expiry cache extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AccessedPolicy implements PolicyInterface { | |
public function __construct($access_count) { /*...*/ } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface ExpireableItemInterface extends Psr\Cache\CacheItemInterface | |
{ | |
public function setExpiryPolicy(PolicyInterface); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface ExpireablePoolInterface extends Psr\Cache\CachePoolInterface | |
{ | |
// .. Whatever. | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface PolicyInterface { | |
// ... Whatever. | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Caches a widget. | |
*/ | |
function set_widget(ExpireablePoolInterface $pool, Widget $widget) | |
{ | |
$key = 'widget.' . $widget->id(); | |
$item = $pool->getItem($key); | |
// Expire this item after 5 reads or 300 seconds (5 minutes), whichever comes first. | |
$item->setExpiryPolicy(new AccessedPolicy(5)); | |
$item->expireAfter(300); | |
$item->set($widget); | |
$pool->save($item); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment