Jump to:

23370 Posts in 18160 Topics by 2864 members

General Questions

SilverStripe Forums » General Questions » Caching not working (Facebook widget example)

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 444 Views
  • Josua
    Avatar
    Community Member
    86 Posts

    Caching not working (Facebook widget example) Link to this post

    Hello all!

    I am making an example of the book SilverStripe 2.4 Module Extension, ...
    The example is a Facebook widget.
    When I show the web page with the plugin, it take a long time to show.
    Then, I applied the cache in the template, as the book says, but I do not notice any improvement.
    Also, if I run with XDebug, every time the page is displayed, the function plugin (Feeds) is executed.
    Apparently, no cache is being done, otherwise the function plugin (Feeds) not be executed.
    What can be happening?

    I am using WAMPServer in Windows 7 / Firefox / http://127.0.0.1

    Thanks,

    Regards,
    Jose A.

    ---------------------------------------
    Page.ss
    ---------------------------------------
    <% cached 'page', LastEdited, CacheSegment %>

    <!doctype html>
    <html lang="$ContentLocale">

    <head>
    <meta charset="utf-8"/>
    <% base_tag %>
    <title><% if MetaTitle %>$MetaTitle<% else %>$Title<% end_if %></title>
    $MetaTags(false)
    <link rel="shortcut icon" href="favicon.ico"/>
    <!--[if lt IE 9]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    </head>

    <body>

    $Layout

    <noscript>
    <br/>&nbsp;<br/>&nbsp;<br/>&nbsp;<br/>&nbsp;<br/>&nbsp;<br/>&nbsp;
    <div><p><b>Please activate JavaScript.</b><br/>Otherwise you won't be able to use all available functions properly...</p></div>
    </noscript>
    </body>
    </html>

    <% end_cached %>

    ------------------------------------------------
    Page.php
    ------------------------------------------------
    protected function CacheSegment() {
    return $_SERVER["REQUEST_URI"];
    }

    ------------------------------------------------
    _config.php
    ------------------------------------------------
    SS_Cache::set_cache_lifetime('any', 3600, 100);

    ------------------------------------------------
    FacebookFeedWidget.php
    ------------------------------------------------
    class FacebookFeedWidget extends Widget {
    ......
       public function Feeds(){

          /**
           * URL for fetchning the information, convert the returned JSON into an array.
           * It is required to use an access_token which in turn mandates https.
           */
          if(!defined('FACEBOOK_ACCESS_TOKEN')){
             user_error('Missing Facebook access token - please get one and add it to your mysite/_config.php: define("FACEBOOK_ACCESS_TOKEN", "&lt;your token&gt;");', E_USER_WARNING);
             return;
          }
          $url = 'https://graph.facebook.com/' . $this->Identifier . '/feed?limit=' . ($this->Limit + 5) . '&access_token=' . FACEBOOK_ACCESS_TOKEN;
    $context = stream_context_create(array('http' => array('header'=>'Connection: close')));

    $facebook = json_decode(file_get_contents($url,false,$context), true);
    ........ Another code
    }

    }

  • Josua
    Avatar
    Community Member
    86 Posts

    Re: Caching not working (Facebook widget example) Link to this post

    Hi!

    Does anyone have any ideas about this?

    Regards,
    Jose A.

    444 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.