Pintlabs cache?

20 views
Skip to first unread message

Mats Hjelm

unread,
May 16, 2013, 8:34:15 AM5/16/13
to untappd-api-d...@googlegroups.com
I guess this question is mainly for Jason but I'm interested in alternative workarounds.

I'm looking in how to add cache to the api calls, I guess it would be best if it was built in to the library. Is this something you're working on Jason?


Maybe it is possible to wrap the call inside an if statement?
Is it that simple? I suck at php so this might take a while to work out...

if $venue file is older than 60 seconds do this...

            try {
                $venue = $untappd->venueInfo($lokalpub);
            } catch (Exception $e) {
                die($e->getMessage());
            }

execute and save $venue in a file

or if $venue file is newer than 60 seconds read from the file instead.

Jason Austin

unread,
May 16, 2013, 9:02:31 AM5/16/13
to untappd-api-d...@googlegroups.com
I'm not really working on that, but if you want to write something and submit a pull request, I'd be happy to integrate it in.

- Jason




--
You received this message because you are subscribed to the Google Groups "Untappd API Developer Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to untappd-api-develop...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Jason Austin

Blog: http://www.jasonawesome.com
twitter:  http://www.twitter.com/jason_austin

Mats Hjelm

unread,
May 16, 2013, 9:39:05 AM5/16/13
to untappd-api-d...@googlegroups.com
I suck at php, barely understands it. I'm not touching the library.

I just tested and found out how to save the json to file and read it back in as if it called the api.
Now I just need to make the if statement to wrap around the call to determine if it should call the api or read the cache file.
If you're interested I post how I did it here. If you can use it you can take it...

/Mats

Greg Avola

unread,
May 16, 2013, 10:10:54 AM5/16/13
to untappd-api-d...@googlegroups.com
Mats,

Are you trying to cache data locally and serve it later?

Thanks,
Greg


--
You received this message because you are subscribed to the Google Groups "Untappd API Developer Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to untappd-api-develop...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
--

Greg Avola
Co-Founder / CTO
Untappd

Mats Hjelm

unread,
May 16, 2013, 10:16:38 AM5/16/13
to untappd-api-d...@googlegroups.com
Yes Greg.

This is how I did, it looks like it works...


            $pubfile    = 'db/cache/venueInfo_'.$lokalpub.'.txt';
           
            $filetime = filemtime($pubfile);
            if($filetime + 60 < time()) {


                try {
                    $venue = $untappd->venueInfo($lokalpub);
                } catch (Exception $e) {
                    die($e->getMessage());
                }
   
                $data = json_encode($venue);
                $fh = fopen($pubfile, 'w');
                fwrite($fh, $data);
                fclose($fh);
            } else {

                $string = file_get_contents($pubfile);
                $venue=json_decode($string);

            }           


Den torsdagen den 16:e maj 2013 kl. 14:34:15 UTC+2 skrev Mats Hjelm:
Reply all
Reply to author
Forward
0 new messages