File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed
Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -143,13 +143,20 @@ function _gist_display_link($matches) {
143143 * The data from the Github API.
144144 */
145145function gist_filter_get_gist($id) {
146- static $gists = array();
147-
148- if (!isset($gists[$id])) {
146+ // Cache ID
147+ $cid = 'gist:' . $id;
148+ // Check if this gist is already in the cache
149+ $gist = cache_get($cid);
150+
151+ if (!$gist) {
152+ // Not available in the cache, so retrive the gist from Github
149153 $url = 'https://api.github.com/gists/' . $id;
150154 $response = drupal_http_request($url, array('headers' => array('Content-Type' => 'application/json')));
151- $gists[$id] = drupal_json_decode($response->data);
155+ $gist = drupal_json_decode($response->data);
156+
157+ // Cache the gist until the next cache flush
158+ cache_set($cid, $gist, 'cache', CACHE_TEMPORARY);
152159 }
153160
154- return $gists[$id] ;
161+ return $gist ;
155162}
You can’t perform that action at this time.
0 commit comments