Last active
December 12, 2015 04:28
-
-
Save haugstrup/4713920 to your computer and use it in GitHub Desktop.
Podio example with Redis caching
This file contains 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 | |
// Setup Podio Client | |
Podio::setup(CLIENT_ID, CLIENT_SECRET); | |
// Setup Redis | |
$redis = new Predis\Client(REDIS_INFO) | |
$my_cache_key = "podio_cache"; | |
if ($redis->exists($my_cache_key)) { | |
// We have a cached copy, use that | |
$my_data = $redis->get($my_cache_key); | |
} | |
else { | |
// No cache or cache expired, contact Podio | |
// Authenticate as an app | |
Podio::authenticate('app', array('app_id' => APP_ID, 'app_token' => APP_TOKEN)); | |
// Get a single item | |
$item = PodioItem::get(ITEM_ID); | |
// Find the value of the 'title' field | |
$my_data = $item->fields['title']->values; | |
// Store in cache | |
$redis->set($my_cache_key, $my_data); | |
$redis->expire($my_cache_key, 60*60*12); // Expire in 12 hours | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment