r38239 - in /trunk/libcache-fastmmap-perl: Cache-FastMmap-CImpl/CImpl.pm Changes FastMmap.pm MANIFEST META.yml debian/changelog debian/control debian/copyright debian/rules t/15.t t/7.t

jawnsy-guest at users.alioth.debian.org jawnsy-guest at users.alioth.debian.org
Thu Jun 18 22:53:47 UTC 2009


Author: jawnsy-guest
Date: Thu Jun 18 22:53:42 2009
New Revision: 38239

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=38239
Log:
* New upstream release (includes bugfixes)
* Now depends on Scalar::Util (provided by perl-base anyway)
* Added /me to Uploaders
* Added some blahblahblah to the control description
* Use the new debian/rules format

Added:
    trunk/libcache-fastmmap-perl/t/15.t
Modified:
    trunk/libcache-fastmmap-perl/Cache-FastMmap-CImpl/CImpl.pm
    trunk/libcache-fastmmap-perl/Changes
    trunk/libcache-fastmmap-perl/FastMmap.pm
    trunk/libcache-fastmmap-perl/MANIFEST
    trunk/libcache-fastmmap-perl/META.yml
    trunk/libcache-fastmmap-perl/debian/changelog
    trunk/libcache-fastmmap-perl/debian/control
    trunk/libcache-fastmmap-perl/debian/copyright
    trunk/libcache-fastmmap-perl/debian/rules
    trunk/libcache-fastmmap-perl/t/7.t

Modified: trunk/libcache-fastmmap-perl/Cache-FastMmap-CImpl/CImpl.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcache-fastmmap-perl/Cache-FastMmap-CImpl/CImpl.pm?rev=38239&op=diff
==============================================================================
--- trunk/libcache-fastmmap-perl/Cache-FastMmap-CImpl/CImpl.pm (original)
+++ trunk/libcache-fastmmap-perl/Cache-FastMmap-CImpl/CImpl.pm Thu Jun 18 22:53:42 2009
@@ -15,7 +15,7 @@
 use strict;
 use warnings;
 
-our $VERSION = '1.30';
+our $VERSION = '1.33';
 
 require XSLoader;
 XSLoader::load('Cache::FastMmap::CImpl', $VERSION);

Modified: trunk/libcache-fastmmap-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcache-fastmmap-perl/Changes?rev=38239&op=diff
==============================================================================
--- trunk/libcache-fastmmap-perl/Changes (original)
+++ trunk/libcache-fastmmap-perl/Changes Thu Jun 18 22:53:42 2009
@@ -1,4 +1,18 @@
 Revision history for Perl extension Cache::FastMmap.
+
+1.33 Thu Jun 18 12:00 2009
+  - Update version in META.yml
+
+1.32 Thu Jun 18 11:55 2009
+  - Better LiveCaches tracking via DESTROY
+
+1.31 Thu Jun 18 11:40 2009
+  - when in raw_values => 0 mode, the write_cb is now
+    correctly called with thawed data, rather than the
+    raw frozen data
+  - empty_on_exit correctly called even when a global
+    cache is left at interpreter exit time (required
+    Scalar::Util qw(weaken) for object tracking)
 
 1.30 Fri May 8  11:10 2009
   - Fix for Mandriva compiler (thanks Jean-Christian Hassler)

Modified: trunk/libcache-fastmmap-perl/FastMmap.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcache-fastmmap-perl/FastMmap.pm?rev=38239&op=diff
==============================================================================
--- trunk/libcache-fastmmap-perl/FastMmap.pm (original)
+++ trunk/libcache-fastmmap-perl/FastMmap.pm Thu Jun 18 22:53:42 2009
@@ -287,7 +287,11 @@
 use warnings;
 use bytes;
 
-our $VERSION = '1.30';
+our $VERSION = '1.33';
+
+# Track currently live caches so we can cleanup in END {}
+#  if we have empty_on_exit set
+our %LiveCaches;
 
 use Cache::FastMmap::CImpl;
 
@@ -525,6 +529,15 @@
   if ($compress) {
     eval "use Compress::Zlib; 1;"
       || die "Could not load Compress::Zlib module: $@";
+  }
+
+  # If using empty_on_exit, need to track used caches
+  my $empty_on_exit = $Self->{empty_on_exit} = int($Args{empty_on_exit} || 0);
+  
+  # Need Scalar::Util::weaken to track open caches
+  if ($empty_on_exit) {
+    eval "use Scalar::Util qw(weaken); 1;"
+      || die "Could not load Scalar::Util module: $@";
   }
 
   # Work out expiry time in seconds
@@ -585,8 +598,8 @@
     = @Args{qw(context read_cb write_cb delete_cb)};
   @$Self{qw(cache_not_found allow_recursive write_back)}
     = (@Args{qw(cache_not_found allow_recursive)}, $write_back);
-  @$Self{qw(empty_on_exit unlink_on_exit enable_stats)}
-    = (@Args{qw(empty_on_exit unlink_on_exit)}, $enable_stats);
+  @$Self{qw(unlink_on_exit enable_stats)}
+    = (@Args{qw(unlink_on_exit)}, $enable_stats);
 
   # Save pid
   $Self->{pid} = $$;
@@ -615,6 +628,10 @@
   # And initialise it
   $Cache->fc_init();
 
+  # Track cache if need to empty on exit
+  weaken($LiveCaches{ref($Self)} = $Self)
+    if $empty_on_exit;
+
   # All done, return PERL hash ref as class
   return $Self;
 }
@@ -900,16 +917,23 @@
   my ($Self, $Cache) = ($_[0], $_[0]->{Cache});
 
   my $Mode = $_[1] || 0;
+  my ($Compress, $RawValues) = @$Self{qw(compress raw_values)};
+
   return $Cache->fc_get_keys($Mode)
-    if $Mode <= 1 || ($Mode == 2 && $Self->{raw_values} && !$Self->{compress});
+    if $Mode <= 1 || ($Mode == 2 && $RawValues && !$Compress);
 
   # If we're getting values as well, and they're not raw, unfreeze them
   my @Details = $Cache->fc_get_keys(2);
+
   for (@Details) {
-    if (defined(my $Value = $_->{value})) {
-      $Value = Compress::Zlib::memGunzip($Value) if $Self->{compress};
-      $Value = ${thaw($Value)} if !$Self->{raw_values};
-      $_->{value} = $Value;
+    my $Val = $_->{value};
+    if (defined $Val) {
+      $Val = Compress::Zlib::memGunzip($Val) if $Compress;
+      if (!$RawValues) {
+        $Val = eval { thaw($Val) };
+        $Val = $$Val if ref($Val);
+      }
+      $_->{value} = $Val;
     }
   }
   return @Details;
@@ -1104,9 +1128,20 @@
 
   my @WBItems = $Cache->fc_expunge($Mode, $write_cb ? 1 : 0, $Len);
 
+  my ($Compress, $RawValues) = @$Self{qw(compress raw_values)};
+
   for (@WBItems) {
     next if !($_->{flags} & FC_ISDIRTY);
-    eval { $write_cb->($Self->{context}, $_->{key}, $_->{value}, $_->{expire_time}); };
+
+    my $Val = $_->{value};
+    if (defined $Val) {
+      $Val = Compress::Zlib::memGunzip($Val) if $Compress;
+      if (!$RawValues) {
+        $Val = eval { thaw($Val) };
+        $Val = $$Val if ref($Val);
+      }
+    }
+    eval { $write_cb->($Self->{context}, $_->{key}, $Val, $_->{expire_time}); };
   }
 }
 
@@ -1118,8 +1153,12 @@
   return $expire_time =~ /^(\d+)\s*([mhdws]?)/i ? $1 * $Times{$2} : 0;
 }
 
-sub DESTROY {
+sub cleanup {
   my ($Self, $Cache) = ($_[0], $_[0]->{Cache});
+
+  # Avoid potential double cleanup
+  return if $Self->{cleaned};
+  $Self->{cleaned} = 1;
 
   # Expunge all entries on exit if requested and in parent process
   if ($Self->{empty_on_exit} && $Cache && $Self->{pid} == $$) {
@@ -1134,6 +1173,21 @@
 
   unlink($Self->{share_file})
     if $Self->{unlink_on_exit} && $Self->{pid} == $$;
+
+}
+
+sub DESTROY {
+  my $Self = shift;
+  $Self->cleanup();
+  delete $LiveCaches{ref($Self)} if $Self->{empty_on_exit};
+}
+
+sub END {
+  while (my (undef, $Self) = each %LiveCaches) {
+    # Weak reference, might be undef already
+    $Self->cleanup() if $Self;
+  }
+  %LiveCaches = ();
 }
 
 sub CLONE {
@@ -1174,7 +1228,7 @@
 Otherwise the defaults seem sensible to cleanup unneeded share files rather than
 leaving them around to accumulate.
 
-=item After 1.28
+=item From 1.29
 
 =over 4
 
@@ -1185,6 +1239,19 @@
 
 =back
 
+=item From 1.31
+
+=over 4
+
+=item *
+
+Before 1.31, if you were using raw_values => 0 mode, then the write_cb
+would be called with raw frozen data, rather than the thawed object.
+From 1.31 onwards, it correctly calls write_cb with the thawed object
+value (eg what was passed to the ->set() call in the first place)
+
+=back
+
 =back
 
 =head1 SEE ALSO

Modified: trunk/libcache-fastmmap-perl/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcache-fastmmap-perl/MANIFEST?rev=38239&op=diff
==============================================================================
--- trunk/libcache-fastmmap-perl/MANIFEST (original)
+++ trunk/libcache-fastmmap-perl/MANIFEST Thu Jun 18 22:53:42 2009
@@ -2,14 +2,14 @@
 Cache-FastMmap-CImpl/CImpl.pm
 Cache-FastMmap-CImpl/CImpl.xs
 Cache-FastMmap-CImpl/Makefile.PL
-Cache-FastMmap-CImpl/unix.c
-Cache-FastMmap-CImpl/win32.c
 Cache-FastMmap-CImpl/mmap_cache.c
 Cache-FastMmap-CImpl/mmap_cache.h
 Cache-FastMmap-CImpl/mmap_cache_internals.h
 Cache-FastMmap-CImpl/mmap_cache_test.c
 Cache-FastMmap-CImpl/ppport.h
 Cache-FastMmap-CImpl/README
+Cache-FastMmap-CImpl/unix.c
+Cache-FastMmap-CImpl/win32.c
 Changes
 FastMmap.pm
 Makefile.PL
@@ -22,6 +22,7 @@
 t/12.t
 t/13.t
 t/14.t
+t/15.t
 t/2.t
 t/3.t
 t/4.t

Modified: trunk/libcache-fastmmap-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcache-fastmmap-perl/META.yml?rev=38239&op=diff
==============================================================================
--- trunk/libcache-fastmmap-perl/META.yml (original)
+++ trunk/libcache-fastmmap-perl/META.yml Thu Jun 18 22:53:42 2009
@@ -1,11 +1,14 @@
-# http://module-build.sourceforge.net/META-spec.html
-#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
-name:         Cache-FastMmap
-version:      1.30
-version_from: FastMmap.pm
-installdirs:  site
-requires:
+--- #YAML:1.0
+name:                Cache-FastMmap
+version:             1.33
+abstract:            Uses an mmap'ed file to act as a shared memory interprocess cache
+license:             ~
+author:              
+    - Rob Mueller <cpan at robm.fastmail.fm>
+generated_by:        ExtUtils::MakeMaker version 6.42
+distribution_type:   module
+requires:     
     Storable:                      0
-
-distribution_type: module
-generated_by: ExtUtils::MakeMaker version 6.30_01
+meta-spec:
+    url:     http://module-build.sourceforge.net/META-spec-v1.3.html
+    version: 1.3

Modified: trunk/libcache-fastmmap-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcache-fastmmap-perl/debian/changelog?rev=38239&op=diff
==============================================================================
--- trunk/libcache-fastmmap-perl/debian/changelog (original)
+++ trunk/libcache-fastmmap-perl/debian/changelog Thu Jun 18 22:53:42 2009
@@ -1,3 +1,13 @@
+libcache-fastmmap-perl (1.33-1) UNRELEASED; urgency=low
+
+  * New upstream release (includes bugfixes)
+  * Now depends on Scalar::Util (provided by perl-base anyway)
+  * Added /me to Uploaders
+  * Added some blahblahblah to the control description
+  * Use the new debian/rules format
+
+ -- Jonathan Yu <frequency at cpan.org>  Thu, 18 Jun 2009 14:33:58 -0400
+
 libcache-fastmmap-perl (1.30-1) unstable; urgency=low
 
   * New upstream release

Modified: trunk/libcache-fastmmap-perl/debian/control
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcache-fastmmap-perl/debian/control?rev=38239&op=diff
==============================================================================
--- trunk/libcache-fastmmap-perl/debian/control (original)
+++ trunk/libcache-fastmmap-perl/debian/control Thu Jun 18 22:53:42 2009
@@ -3,7 +3,8 @@
 Priority: optional
 Build-Depends: debhelper (>= 7), perl (>= 5.8.0-7)
 Maintainer: Debian Perl Group <pkg-perl-maintainers at lists.alioth.debian.org>
-Uploaders: Krzysztof Krzyżaniak (eloy) <eloy at debian.org>
+Uploaders: Krzysztof Krzyżaniak (eloy) <eloy at debian.org>,
+ Jonathan Yu <frequency at cpan.org>
 Homepage: http://search.cpan.org/dist/Cache-FastMmap/
 Vcs-Svn: svn://svn.debian.org/pkg-perl/trunk/libcache-fastmmap-perl/
 Vcs-Browser: http://svn.debian.org/viewsvn/pkg-perl/trunk/libcache-fastmmap-perl/
@@ -12,8 +13,17 @@
 Package: libcache-fastmmap-perl
 Architecture: any
 Depends: ${misc:Depends}, ${perl:Depends}, ${shlibs:Depends}
-Description: Mmap'ed file as a shared memory interprocess cache
- Cache::FastMmap is a shared memory cache through an mmap'ed file. It's core 
- is written in C for performance. It uses fcntl locking to ensure multiple 
- processes can safely access the cache at the same time. It uses a basic LRU 
- algorithm to keep the most used entries in the cache.
+Description: Perl module providing a mmap'ed cache
+ Cache::FastMmap uses the mmap system call to establish an interprocess shared
+ memory cache. Its core code is written in C, which can provide significant
+ performance compared to a Pure Perl implementation such as Cache::Mmap. It can
+ handle rather large pages without the socket connection and latency of using
+ full-fledged databases where long-term persistence is unnecessary.
+ .
+ Since the algorithm uses a dual-level hashing system (a hash is used to find
+ a page, then another hash within each page to find a given slot), most get
+ calls can execute in constant O(1) time. The system uses fcntl to handle
+ concurrent access, but only locks individual pages to reduce contention. The
+ oldest (least recently used) data is evicted from the cache first, making
+ this cache implementation most suitable for cases when old data is unlikely
+ to be searched.

Modified: trunk/libcache-fastmmap-perl/debian/copyright
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcache-fastmmap-perl/debian/copyright?rev=38239&op=diff
==============================================================================
--- trunk/libcache-fastmmap-perl/debian/copyright (original)
+++ trunk/libcache-fastmmap-perl/debian/copyright Thu Jun 18 22:53:42 2009
@@ -5,21 +5,22 @@
 Upstream-Name: Cache-FastMmap
 
 Files: *
-Copyright: 
-    © 2003-2009 by FastMail IP Partners
+Copyright: 2003-2009, FastMail IP Partners
 License-Alias: Perl
 License: Artistic | GPL-1+
 
 Files: ppport.h
-Copyright:
-    Version 2.x, Copyright (C) 2001, Paul Marquess.
-    Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
+Copyright: 2004-2009, Marcus Holland-Moritz <mhx-cpan at gmx.net>
+ 2001, Paul Marquess <pmqs at cpan.org> (Version 2.x)
+ 1999, Kenneth Albanowski <kjahds at kjahds.com> (Version 1.x)
 License-Alias: Perl
 License: Artistic | GPL-1+
 
 Files: debian/*
-Copyright: 2005-2009, various members of the Debian Perl Group,
- cf. debian/changelog
+Copyright: 2009, Jonathan Yu <frequency at cpan.org>
+ 2009, gregor hermann <gregoa at debian.org>
+ 2009, Ansgar Burchardt <ansgar at 43-1.org>
+ 2005-2009, Krzysztof Krzyzaniak (eloy) <eloy at debian.org>
 License: Artistic | GPL-1+
 
 License: Artistic

Modified: trunk/libcache-fastmmap-perl/debian/rules
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcache-fastmmap-perl/debian/rules?rev=38239&op=diff
==============================================================================
--- trunk/libcache-fastmmap-perl/debian/rules (original)
+++ trunk/libcache-fastmmap-perl/debian/rules Thu Jun 18 22:53:42 2009
@@ -1,22 +1,4 @@
 #!/usr/bin/make -f
 
-build: build-stamp
-build-stamp:
-	dh build
-	touch build-stamp
-
-clean:
-	dh clean
-
-install: build install-stamp
-install-stamp:
-	dh install
-	touch install-stamp
-
-binary-arch: install
-	dh binary-arch
-
-binary-indep: install
-	
-
-binary: binary-arch binary-indep
+%:
+	dh $@

Added: trunk/libcache-fastmmap-perl/t/15.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcache-fastmmap-perl/t/15.t?rev=38239&op=file
==============================================================================
--- trunk/libcache-fastmmap-perl/t/15.t (added)
+++ trunk/libcache-fastmmap-perl/t/15.t Thu Jun 18 22:53:42 2009
@@ -1,0 +1,57 @@
+
+#########################
+
+use Test::More tests => 9;
+BEGIN { use_ok('Cache::FastMmap') };
+use Data::Dumper;
+use strict;
+
+#########################
+
+# Test writeback and cache_not_found option
+
+# Test a backing store just made of a local hash
+my %BackingStore = (
+  foo => { key1 => '123abc' },
+  bar => undef
+);
+
+my %OrigBackingStore = %BackingStore;
+
+my $RCBCalled = 0;
+
+my $FC = Cache::FastMmap->new(
+  cache_not_found => 1,
+  raw_values => 0,
+  init_file => 1,
+  num_pages => 89,
+  page_size => 1024,
+  context => \%BackingStore,
+  read_cb => sub { $RCBCalled++; return $_[0]->{$_[1]}; },
+  write_cb => sub { $_[0]->{$_[1]} = $_[2]; },
+  delete_cb => sub { delete $_[0]->{$_[1]} },
+  write_action => 'write_back'
+);
+
+ok( defined $FC );
+
+# Should pull from the backing store
+ok( eq_hash( $FC->get('foo'), { key1 => '123abc' } ),  "cb get 1");
+is( $FC->get('bar'), undef,  "cb get 2");
+is( $RCBCalled, 2,  "cb get 2");
+
+# Should be in the cache now
+ok( eq_hash( $FC->get('foo'), { key1 => '123abc' } ),  "cb get 3");
+is( $FC->get('bar'), undef,  "cb get 4");
+is( $RCBCalled, 2,  "cb get 2");
+
+# Need to make them dirty
+$FC->set('foo', { key1 => '123abc' });
+$FC->set('bar', undef);
+
+# Should force cache data back to backing store
+%BackingStore = ();
+$FC->empty();
+
+ok( eq_hash(\%BackingStore, \%OrigBackingStore), "items match 1" . Dumper(\%BackingStore, \%OrigBackingStore));
+

Modified: trunk/libcache-fastmmap-perl/t/7.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcache-fastmmap-perl/t/7.t?rev=38239&op=diff
==============================================================================
--- trunk/libcache-fastmmap-perl/t/7.t (original)
+++ trunk/libcache-fastmmap-perl/t/7.t Thu Jun 18 22:53:42 2009
@@ -1,7 +1,7 @@
 
 #########################
 
-use Test::More tests => 11;
+use Test::More tests => 13;
 BEGIN { use_ok('Cache::FastMmap') };
 use strict;
 
@@ -27,7 +27,8 @@
   read_cb => sub { return $_[0]->{$_[1]}; },
   write_cb => sub { $_[0]->{$_[1]} = $_[2]; },
   delete_cb => sub { delete $_[0]->{$_[1]} },
-  write_action => 'write_back'
+  write_action => 'write_back',
+  empty_on_exit => 1
 );
 
 ok( defined $FC );
@@ -92,6 +93,23 @@
 # So all written items should be in backing store
 ok( eq_hash(\%WrittenItems, \%BackingStore), "items match 3");
 
+my @Keys = $FC->get_keys(0);
+ok( scalar(@Keys) == 0, "no items left in cache" );
+
+%WrittenItems = %BackingStore = ();
+
+# Put 3000 items in the cache
+for (1 .. 3000) {
+  my ($Key, $Val) = (RandStr(10), RandStr(100));
+  $FC->set($Key, $Val);
+  $WrittenItems{$Key} = $Val;
+}
+
+# empty_on_exit is set, so this should push to backing store
+$FC = undef;
+
+ok( eq_hash(\%WrittenItems, \%BackingStore), "items match 4");
+
 sub RandStr {
   return join '', map { chr(ord('a') + rand(26)) } (1 .. $_[0]);
 }




More information about the Pkg-perl-cvs-commits mailing list