From d78fc53f815677152cfea184ade88dffebebb39a Mon Sep 17 00:00:00 2001 From: Paul Weinstein Date: Tue, 13 Aug 2019 20:11:51 +0000 Subject: [PATCH] Memecache working as intended --- lib/pre.php | 36 ++++++++++++++++++++++++------------ www/index.php | 7 +++---- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/lib/pre.php b/lib/pre.php index 28fbd35..578c651 100644 --- a/lib/pre.php +++ b/lib/pre.php @@ -10,24 +10,25 @@ if ( $location != 'local' ) { $memcache = new Memcache; - $memcache->addServer( $mhost, $mport ); + $memcache->connect( $mhost, $mport ); - if ( $posts = $memcache->get( 'latest' )) { + if ( $latest = $memcache->get( 'latest' )) { - $posts = $memcache->get( 'latest' ); + $latest = $memcache->get( 'latest' ); + $latestDate = $memcache->get( 'latest_date' ); $githubEvents = $memcache->get( 'github' ); $recent = $memcache->get( 'flickr_recent' ); $info = $memcache->get( 'flickr_info' ); - $books = $memcache->get( 'goodreads' ); - $instaData = $memcache->get( 'instagram' ); - $tweets = $memcache->get( 'tweets' ); + $book = $memcache->get( 'goodreads' ); + $instaObj = $memcache->get( 'instagram' ); + $tweets = $memcache->get( 'twitter' ); } } if (( $location == 'local' ) OR - ( !$posts = $memcache->get( 'latest' ))) { + ( !$latest = $memcache->get( 'latest' ))) { //$seti = new RPC; @@ -53,13 +54,15 @@ $instaObj = $elsewhere->getInstaPosts( $instaToken, 1 ); $tweets = json_decode( $twitter->setGetfield( $getfield )->buildOauth( $twitterURL, $requestMethod )->performRequest() ); + $book['link'] = $books[0]->link; + $book['title'] = $books[0]->title; + if( $location != 'local' ) { - $memcache->set( 'latest', $latest, MEMCACHE_COMPRESSED, 3600 ); $memcache->set( 'github', $githubEvents, MEMCACHE_COMPRESSED, 3600 ); $memcache->set( 'flickr_recent', $recent, MEMCACHE_COMPRESSED, 3600 ); $memcache->set( 'flickr_info', $info, MEMCACHE_COMPRESSED, 3600 ); - $memcache->set( 'goodreads', $books, MEMCACHE_COMPRESSED, 3600 ); + $memcache->set( 'goodreads', $book, MEMCACHE_COMPRESSED, 3600 ); $memcache->set( 'instagram', $instaObj, MEMCACHE_COMPRESSED, 3600 ); $memcache->set( 'twitter', $tweets, MEMCACHE_COMPRESSED, 3600 ); @@ -94,8 +97,17 @@ // Reset our pointer to the top of the array reset( $posts ); - // Pull our winner - $latest = key( $posts ); - $latestDate = gmdate( "M d Y", $posts[$latest] ); + if (( $location == 'local' ) OR + ( !$latest = $memcache->get( 'latest' ))) { + + // Pull our winner + $latest = key( $posts ); + $latestDate = gmdate( "M d Y", $posts[$latest] ); + + $memcache->set( 'latest', $latest, MEMCACHE_COMPRESSED, 3600 ); + $memcache->set( 'latest_date', $latestDate, MEMCACHE_COMPRESSED, 3600 ); + $memcache->set( 'latest_post', $post, MEMCACHE_COMPRESSED, 3600 ); + + } ?> diff --git a/www/index.php b/www/index.php index 5fe2c26..d4c6ae7 100644 --- a/www/index.php +++ b/www/index.php @@ -86,13 +86,12 @@
  • Goodreads
  • Facebook
  • "); - +/* $postData = ""; $userPosts = $fb->get("/526081044/feed", $accessToken); $postBody = $userPosts->getDecodedBody(); @@ -110,7 +109,7 @@ } } } - + */ $template->outputHTML("
  • Flickr