Dec. 23rd, 2012

[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

September 2022

S M T W T F S
    123
45678910
1112131415 1617
18192021222324
252627282930 

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 3rd, 2025 03:29 pm
Powered by Dreamwidth Studios