FBML Caching
Problem
I’d like to take advantage of Facebook’s FBML caching to store a block of FBML that I use often.
Solution
Use the fb:ref tag. There are two ways to use it, depending on how you’ve
architected your app:
- By handle
If you’re developing heavily in the Facebook API, this is probably the better method for you. Use the API call
setRefHandleto initialize your handle:$facebook->api_client->fbml_setRefHandle("MyUniqueAppHandle", "Some FBML Content");Then insert the
fb:reftag in your FBML to pull the block out and display it:<fb:ref handle="MyUniqueAppHandle" />
Now when you want to update the content, just call
setRefHandleagain with new FBML and it will change everywhere you’ve putfb:reftags.- By URL
If your app is based more on different files or pages on a server, you can still put FBML into the cache by giving it a unique URL. Create a page that only renders out the block you’d like stored, and then use the alternate form of the
fb:reftag:<fb:ref url="http://www.someserver.com/cacheThisPage.php" />
When you want to change the content, update your page on your server and then make a simple API call to tell Facebook that it needs to reindex that URL:
$facebook->api_client->fbml.refreshRefUrl("http://www.someserver .com/cacheThisPage.php")
Discussion
There are lots of places you might use this—really wherever you have a block of relatively static content you want to display—but the best use is probably for Profile Boxes that aren’t user-specific. In that case, you’ll want to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access