Storing Data To Access In All Controllers

Hi ,

I have need to implement few facebook features in my application.

The problem is I need to do some server side processing of data received from Facebook. Example the friendList.

I will be doing this processing in almost all conroller.

I dont think its feasible to make a call in each controller to get facebook friends list.

Is there any way I can store the data temporary and access it in all controllers.

I dont want to save it to session. I guess it will make data slow.

and i cannot permanently save the friend list in my database I guess Issue with facebook policy.

Any directions? suggestion? please…

if you do not want to use session (but it still be much faster than fetching data in every controller) you can use cache…

you can implement it in your Controller.php component with which you can access in every controller. I have this in protected/components/ folder. you can write in before action controller. hope this following little code snippet can help you

its like this. you can write in before action so that you can access anywhere in site.




<?php


/**

 * Controller is the customized base controller class.

 * All controller classes for this application should extend from this base class.

 */

class Controller extends CController

{

	public $bodyId;

	public $user;


public function beforeAction($action)

	{

		if(isset($_GET['r']))

			Yii::app()->clientScript->registerCoreScript('jquery');

		else

			Yii::app()->theme='xyz';


		// Get Facebook sessions to work in IE

		header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');

....

....


//you can  write something here i'm accessing through out the site.

// get the terms

		$this->terms = Model::model()->findByAttributes(array('name'=>'terms'))->value;





 }

}

Thanks,

@redguy

Hi redguy… I am new to Yii. Is it ok to save save big arrays in cache

for so many users?

@developer!

I guess you are access the data from a model to make it available every where

but facebook policy says you cannot save data like freinds list in your

own database. :(

well… it depends. If you want to reduce number of calls to remote service to MUST store the data somehow… I mean it is rather only way to achieve what you want, but you should use cache mechanizm with some garbage collector or LRU (least recently used) removing policy to keep the cache from growing infinitely. You could try memcached (it has LRU removing policy) or some cache in database table, where you could periodically remove old records. Avoid file cache as it does not delete unused cache entries.

Session would also work well and there is garbage collector for sessions, but session is loaded every time it is needed not matter if you use all stored data or not, so it is some overhead for request that do not need this data. So if you need that data in EVERY controller and EVERY request (or almost every) - use session.