changelog_bot (changelog_bot) wrote in changelog,
changelog_bot
changelog_bot
changelog

[livejournal] r19056: LJSUP-8510: Portal "LJ Times"

Committer: emazin
LJSUP-8510: Portal "LJ Times"
U   branches/LJTimes/cgi-bin/LJ/MemCache.pm
U   branches/LJTimes/cgi-bin/LJ/MemCacheable.pm
Modified: branches/LJTimes/cgi-bin/LJ/MemCache.pm
===================================================================
--- branches/LJTimes/cgi-bin/LJ/MemCache.pm	2011-05-13 01:02:59 UTC (rev 19055)
+++ branches/LJTimes/cgi-bin/LJ/MemCache.pm	2011-05-13 01:20:21 UTC (rev 19056)
@@ -623,6 +623,21 @@
     return $value;
 }
 
+#add lock key with little expire, set if success, else wait and try another time
+#TODO
+sub get_or_set_with_lock {
+    my ( $key, $code, $expire ) = @_;
+
+    my $value = LJ::MemCache::get($key);
+
+    unless ($value) {
+        $value = $code->();
+        LJ::MemCache::set( $key, $value, $expire );
+    }
+
+    return $value;
+}
+
 ### OBJECT SERIALIZATION METHODS ###
 
 sub array_to_hash {

Modified: branches/LJTimes/cgi-bin/LJ/MemCacheable.pm
===================================================================
--- branches/LJTimes/cgi-bin/LJ/MemCacheable.pm	2011-05-13 01:02:59 UTC (rev 19055)
+++ branches/LJTimes/cgi-bin/LJ/MemCacheable.pm	2011-05-13 01:20:21 UTC (rev 19056)
@@ -51,6 +51,27 @@
     return $class->_memcache_hashref_to_object(\%hash);
 }
 
+sub _load_from_memcache_multi {
+    my $class = shift;
+    my $ids = shift;
+    my %ret = ();
+
+    my @keys = map { $class->_memcache_key($_) } @$ids;
+    my $data = LJ::MemCache::get_multi(@keys);
+    
+    my ($version, @props) = $class->_memcache_stored_props;
+    for my $key (keys %$data) {
+        unless ($ret{$key}->[0]==$version) {
+            $ret{$key} = undef;
+            next;
+        }
+        my %hash = map { $props[$_] => $data->[$_+1] } (0 .. $#props);
+        $ret{$key} = $class->_memcache_hashref_to_object(\%hash);
+    }
+
+    return \%ret;
+}
+
 ## warning: instance or class method. 
 ## $id may be absent when calling on instance.
 sub _remove_from_memcache {

Tags: changelog_bot, livejournal, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments