<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dw="https://www.dreamwidth.org">
  <id>tag:dreamwidth.org,2009-04-10:30813</id>
  <title>Dreamwidth Development Training</title>
  <subtitle>Dreamwidth Development Training</subtitle>
  <author>
    <name>Dreamwidth Development Training</name>
  </author>
  <link rel="alternate" type="text/html" href="https://dw-dev-training.dreamwidth.org/"/>
  <link rel="self" type="text/xml" href="https://dw-dev-training.dreamwidth.org/data/atom"/>
  <updated>2012-12-23T15:44:13Z</updated>
  <dw:journal username="dw_dev_training" type="community"/>
  <entry>
    <id>tag:dreamwidth.org,2009-04-10:30813:42012</id>
    <author>
      <name>Simon</name>
    </author>
    <dw:poster user="swaldman"/>
    <link rel="alternate" type="text/html" href="https://dw-dev-training.dreamwidth.org/42012.html"/>
    <link rel="self" type="text/xml" href="https://dw-dev-training.dreamwidth.org/data/atom/?itemid=42012"/>
    <title>Using memcache</title>
    <published>2012-12-23T15:44:13Z</published>
    <updated>2012-12-23T15:44:13Z</updated>
    <category term="memcache"/>
    <dw:music>Panama Rag</dw:music>
    <dw:security>public</dw:security>
    <dw:reply-count>4</dw:reply-count>
    <content type="html">Posted by: &lt;span lj:user='swaldman' style='white-space: nowrap;' class='ljuser'&gt;&lt;a href='https://swaldman.dreamwidth.org/profile'&gt;&lt;img src='https://www.dreamwidth.org/img/silk/identity/user.png' alt='[personal profile] ' width='17' height='17' style='vertical-align: text-bottom; border: 0; padding-right: 1px;' /&gt;&lt;/a&gt;&lt;a href='https://swaldman.dreamwidth.org/'&gt;&lt;b&gt;swaldman&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is the first time I've tried using memcache, so I thought I'd post here and check I'm doing it right.&lt;br /&gt;This is perhaps a slightly unusual application, because it isn't for caching something that's in the db.&lt;br /&gt;&lt;br /&gt;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:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
#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;
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So, does the above make sense? Am I doing things correctly? Is there a convention as to what the key should be called?&lt;br /&gt;&lt;br /&gt;Thanks :-)&lt;br /&gt;&lt;br /&gt;&lt;img src="https://www.dreamwidth.org/tools/commentcount?user=dw_dev_training&amp;ditemid=42012" width="30" height="12" alt="comment count unavailable" style="vertical-align: middle;"/&gt; comments</content>
  </entry>
</feed>
