Using memcache
Dec. 23rd, 2012 03:39 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
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:
So, does the above make sense? Am I doing things correctly? Is there a convention as to what the key should be called?
Thanks :-)
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 :-)