[personal profile] swaldman
This is the first time I've tried using memcache, so I thought I'd post here and check I'm doing it right.
This is perhaps a slightly unusual application, because it isn't for caching something that's in the db.

Scenario: There is a Twitter config variable that we need to know, which changes occasionally. There's a Twitter API call to find it out, but they ask that people don't call this more than once a day. So, my intention is along these lines:

#allow an override, and also a fallback for sites that don't use memcache.
return $LJ::MYVARIABLE if $LJ::MYVARIABLE

my $value = LJ::MemCache::get( 'mykey' );
return $value if $value;

#we clearly don't have it at present
#Do stuff to get the value from Twitter.

LJ::MemCache::set( 'mykey', $value, 24*60*60 );
return $value;


So, does the above make sense? Am I doing things correctly? Is there a convention as to what the key should be called?

Thanks :-)

Profile

dw_dev_training: The stylised 'd', with the word 'dev' above, and the word 'training' at the side, representing the dw_dev_training comm. (Default)
Dreamwidth Development Training

January 2017

S M T W T F S
1234567
891011121314
151617 18192021
22232425262728
293031    

Syndicate

RSS Atom

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 25th, 2017 10:37 pm
Powered by Dreamwidth Studios