<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>Dave Dash</title>
 <link href="http://davedash.com/tag/cache/atom.xml" rel="self"/>
 <link href="http://davedash.com/tag/cache"/>
 <updated>2012-04-07T22:42:44-07:00</updated>
 <id>http://davedash.com/</id>
 <author>
   <name>Dave Dash</name>
   <email>dd+atom1@davedash.com</email>
 </author>

 
 <entry>
   <title>Serving Firefox xpi extensions over ssl/https</title>
   <link href="http://davedash.com/2008/01/22/serving-firefox-xpi-extensions-over-sslhttps/"/>
   <updated>2008-01-22T00:00:00-08:00</updated>
   <id>http://davedash.com/2008/01/22/serving-firefox-xpi-extensions-over-sslhttps</id>
   <content type="html">&lt;p&gt;[tags]firefox, cache, xpi, https[/tags]&lt;/p&gt;

&lt;p&gt;Apparently serving XPI extensions over HTTPS is a headache.  What happens is you may have a link to an XPI served over HTTPS, but Firefox will ask intercept the download and ask you to add your domain to the allowed hosts.  After allowing it, you can't re-download the file (it gets cached, incorrectly, even if you request it to not do so).&lt;/p&gt;

&lt;p&gt;So the workaround is this:&lt;/p&gt;

&lt;p&gt;Don't link directly to the XPI file.  Link to an action (e.g. &lt;code&gt;/getxpi&lt;/code&gt;).  Have this action link to the actual XPI file with a random &lt;code&gt;GET&lt;/code&gt; parameter, e.g. &lt;code&gt;https://mydomain.com/xpi/myextension.xpi?ts=123456&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This will result in any XPI downloaded from &lt;code&gt;/getxpi&lt;/code&gt; to not be cached.&lt;/p&gt;

&lt;p&gt;This is a cruddy work-around for a problem with Firefox, but unfortunately I'm not a XUL hacker.&lt;/p&gt;

&lt;p&gt;-d&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Caching REST with sfFunctionCache</title>
   <link href="http://davedash.com/2007/04/07/caching-rest-with-sffunctioncache/"/>
   <updated>2007-04-07T00:00:00-07:00</updated>
   <id>http://davedash.com/2007/04/07/caching-rest-with-sffunctioncache</id>
   <content type="html">&lt;p&gt;[tags]geocoding, caching, REST, symfony, Cache_Lite, php, cache, sfFunctionCache[/tags]&lt;/p&gt;

&lt;p&gt;For &lt;a href=&quot;http://reviewsby.us/&quot;&gt;reviewsby.us&lt;/a&gt; we do a lot of geocoding.  To facilitate we use &lt;a href=&quot;http://developer.yahoo.com/maps/rest/V1/geocode.html&quot;&gt;Yahoo! Geocoding API&lt;/a&gt;.  This helps us normalize data, obtain latitude and longitude, interpret location specific searches.&lt;/p&gt;

&lt;p&gt;These &lt;acronym title=&quot;REpresentational State Transfer&quot;&gt;REST&lt;/acronym&gt; queries happen a lot and will continue to happen, but this data that Yahoo! provides is fairly static.  We're basically querying a database of sorts.  So it makes sense that we should cache this data.&lt;/p&gt;

&lt;p&gt;We'll demonstrate how to cache these queries using &lt;a href=&quot;http://symfony-project.com/&quot;&gt;symfony&lt;/a&gt;'s &lt;a href=&quot;http://www.symfony-project.com/book/trunk/18-Performance#Caching%20the%20Result%20of%20a%20Function%20Call&quot;&gt;&lt;code&gt;sfFunctionCache&lt;/code&gt;&lt;/a&gt; class.&lt;/p&gt;

&lt;!--more--&gt;


&lt;p&gt;I wrote a wrapper (I'll release it as a plugin if requested) for the &lt;a href=&quot;http://developer.yahoo.com/maps/rest/V1/geocode.html&quot;&gt;Geocoding API&lt;/a&gt;, the bulk of the work (the &lt;acronym title=&quot;REpresentational State Transfer&quot;&gt;REST&lt;/acronym&gt; call) occurs in a function called &lt;code&gt;doQueryGIS&lt;/code&gt;:&lt;/p&gt;

&lt;div&gt;&lt;textarea name=&quot;code&quot; class=&quot;php&quot;&gt;
        public static function doQueryGIS($location)
        {
            $url               = sfConfig::get('app_yahoo_geocode');

            $query             = array();
            $query['appid']    = sfConfig::get('app_yahoo_app_id');
            $query['location'] = $location;
            $query['output']   = 'php';

            $url .= '?' . http_build_query($query,null,'&amp;');    
              $curl = curl_init($url);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            $response = curl_exe c($curl); 
              // note there should be no space between curl_exe and c($curl) 
              // wordpress is just dumb
        

            if ($response != 'Array') 
            {
                return unserialize($response);
            } 
            else 
            {
                throw new sfException('Yahoo! GeoCoder does not understand: &quot;'. $location . &quot;\&quot;\n&quot;);
            }
            return false;   
            
            
        }

&lt;/textarea&gt;&lt;/div&gt;


&lt;p&gt;The call to this function is always wrapped with &lt;code&gt;queryGIS&lt;/code&gt;:&lt;/p&gt;

&lt;div&gt;&lt;textarea name=&quot;code&quot; class=&quot;php&quot;&gt;
      protected function queryGIS()
        {
            $function_cache_dir = sfConfig::get('sf_cache_dir').'/function';
            $cache = new sfFunctionCache($function_cache_dir);
            $this-&gt;rawData = $cache-&gt;call(array('YahooGeo','doQueryGIS'), $this-&gt;rawLocation);
            return $this-&gt;rawData;
            
        }
&lt;/textarea&gt;&lt;/div&gt;


&lt;p&gt;This wrapper creates a &lt;code&gt;sfFunctionCache&lt;/code&gt; objet and calls the function and caches it for subsequent queries.&lt;/p&gt;

&lt;p&gt;What this means is once Yahoo! teaches &lt;a href=&quot;http://reviewsby.us/&quot;&gt;reviewsby.us&lt;/a&gt; that India is located at (25.42&amp;deg;, 77.830002&amp;deg;) and that the precision is 'country' we remember it in the future.&lt;/p&gt;

&lt;p&gt;These features will be incorporated into future versions of &lt;a href=&quot;http://reviewsby.us/&quot;&gt;reviewsby.us&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 

</feed>

