This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Facebook and the Symfony Cache

Notes and reports about symfony 1.0.x stable

Facebook and the Symfony Cache

by jonhfx » Sat Jul 05, 2008 10:45 pm

Hi folks!

Hopefully someone with experience using symfony to develop facebook applications can answer this one.

I am caching a module action, and everything appears to be working fine. However, symfony does not write the cache files if the request is made through facebook. If I make a request to the application's domain directly, the cache files are written. If I make the request through facebook, the cache files are not written.

Does anyone have some insight on this?
Jonathan Montgomery
http://jonocode.wordpress.com
jonhfx
Member
 
Posts: 37
Joined: Fri Jan 18, 2008 3:25 am

Re: Facebook and the Symfony Cache

by francois » Sun Jul 06, 2008 12:01 am

Dunno how you plugged Facebook in, but caching is deactivated for POST requests and requests with GET arguments. That may be why.
francois
Faithful Member
 
Posts: 1638
Joined: Sat Oct 22, 2005 4:56 pm

Re: Facebook and the Symfony Cache

by jonhfx » Sun Jul 06, 2008 12:17 am

Thanks Francois!

You're right. The Facebook API is probably passing some URL parameters back and forth under the hood, in order to complete some authentication.
Jonathan Montgomery
http://jonocode.wordpress.com
jonhfx
Member
 
Posts: 37
Joined: Fri Jan 18, 2008 3:25 am

Re: Facebook and the Symfony Cache

by netrix » Tue Jun 30, 2009 1:35 pm

Sorry to dredge up this old post but have you figured any way around this?
netrix
Member
 
Posts: 42
Joined: Sun Nov 04, 2007 3:55 pm

Re: Facebook and the Symfony Cache

by jonhfx » Tue Jun 30, 2009 10:55 pm

Sorry, but unfortunately I abandoned the project long ago and I can't remember if I could get caching to work. I'll probably come back to this issue some time in the future under Symfony 1.2.
Jonathan Montgomery
http://jonocode.wordpress.com
jonhfx
Member
 
Posts: 37
Joined: Fri Jan 18, 2008 3:25 am

Re: Facebook and the Symfony Cache

by kristopher1 » Tue Aug 30, 2011 1:56 pm

If someone looking for solution in symfony 1.4, problem is in sfViewCacheManager class.
Facebook is communicating with application by POST request.
Class sfViewCacheManager has 2 methods witch check request method to do cache.

Code: Select all
public function isCacheable($internalUri)
  {
    if ($this->request instanceof sfWebRequest && !$this->request->isMethod(sfRequest::GET))
    {
      return false;
    }
........

Code: Select all
public function isActionCacheable($moduleName, $actionName)
  {
    if ($this->request instanceof sfWebRequest && !$this->request->isMethod(sfRequest::GET))
    {
      return false;
    }
.......


In my opinion for facebook we should create new sfViewCacheManager class. My example:

Code: Select all
class rfViewCacheManagerFacebook extends sfViewCacheManager
{

    /**
     * Returns true if the current content is cacheable.
     *
     * Possible break in backward compatibility: If the sf_lazy_cache_key
     * setting is turned on in settings.yml, this method is not used when
     * initially checking a partial's cacheability.
     *
     * @see sfPartialView, isActionCacheable()
     *
     * @param  string $internalUri  Internal uniform resource identifier
     *
     * @return bool true, if the content is cacheable otherwise false
     */
    public function isCacheable($internalUri) {
        if (!$this->request instanceof sfWebRequest) {
            return false;
        }

        list($route_name, $params) = $this->controller->convertUrlStringToParameters($internalUri);

        if (!isset($params['module'])) {
            return false;
        }

        $this->registerConfiguration($params['module']);

        if (isset($this->cacheConfig[$params['module']][$params['action']])) {
            return ($this->cacheConfig[$params['module']][$params['action']]['lifeTime'] > 0);
        } else if (isset($this->cacheConfig[$params['module']]['DEFAULT'])) {
            return ($this->cacheConfig[$params['module']]['DEFAULT']['lifeTime'] > 0);
        }

        return false;
    }

    /**
     * Returns true if the action is cacheable.
     *
     * @param  string $moduleName A module name
     * @param  string $actionName An action or partial template name
     *
     * @return boolean True if the action is cacheable
     *
     * @see isCacheable()
     */
    public function isActionCacheable($moduleName, $actionName) {
        if (!$this->request instanceof sfWebRequest) {
            return false;
        }

        $this->registerConfiguration($moduleName);

        if (isset($this->cacheConfig[$moduleName][$actionName])) {
            return $this->cacheConfig[$moduleName][$actionName]['lifeTime'] > 0;
        } else if (isset($this->cacheConfig[$moduleName]['DEFAULT'])) {
            return $this->cacheConfig[$moduleName]['DEFAULT']['lifeTime'] > 0;
        }

        return false;
    }
}


On this solution we must remember to NOT cache partials, components etc that view is generated with POST requests.
My cache.yml

Code: Select all
default:
  enabled:     false
  with_layout: false
  lifetime:    86400

_footer:
  enabled:     true;
  lifetime:    86400 


factories.yml
Code: Select all
prod:
  view_cache_manager:
    class: rfViewCacheManagerFacebook
    param:
      cache_key_use_vary_headers: true
      cache_key_use_host_name:    true

I put it here because its show on 1 place in google ;)
Sorry for my English ;)
kristopher1
Junior Member
 
Posts: 1
Joined: Tue Aug 30, 2011 1:31 pm

Re: Facebook and the Symfony Cache

by pedrocasado » Thu May 17, 2012 6:41 pm

Do you have any solution for partials and components ?

I'm running the same problem.
pedrocasado
Junior Member
 
Posts: 9
Joined: Sat Dec 11, 2010 12:18 am