ALT Linux Sisyphus discussions
 help / color / mirror / Atom feed
* [sisyphus] perldoc cache
@ 2005-04-21 21:20 Alexey Tourbin
  0 siblings, 0 replies; only message in thread
From: Alexey Tourbin @ 2005-04-21 21:20 UTC (permalink / raw)
  To: Sisyphus


[-- Attachment #1.1: Type: text/plain, Size: 568 bytes --]

Я реализовал кеширование в perldoc (для pod2man | nroff).
Чтобы кеширование включилось, нужно создать каталог ~/.perldoc.

* Fri Apr 22 2005 Alexey Tourbin <at@altlinux> 3.14-alt2
- implemented cache for nroff formatted output (mkdir ~/.perldoc)

$ mkdir ~/.perldoc
$ time perldoc perlre >/dev/null
perldoc perlre > /dev/null  3,98s user 0,06s system 99% cpu 4,064 total
$ ls ~/.perldoc
_usr_bin_pod2man_lax_usr_lib_perl5_pod_perlre_pod_nroff_man
$ time perldoc perlre >/dev/null
perldoc perlre > /dev/null  0,72s user 0,03s system 98% cpu 0,760 total
$

[-- Attachment #1.2: perldoc-3.14-alt-man-cache.patch --]
[-- Type: text/plain, Size: 935 bytes --]

--- Pod-Perldoc-3.14/lib/Pod/Perldoc/ToMan.pm-	2004-12-01 01:20:19 +0300
+++ Pod-Perldoc-3.14/lib/Pod/Perldoc/ToMan.pm	2005-04-22 01:08:03 +0400
@@ -38,6 +38,9 @@ sub parse_from_file {
   my $self = shift;
   my($file, $outfh) = @_;
 
+  require Cwd;
+  $file = Cwd::realpath($file) || $file;
+
   my $render = $self->{'__nroffer'} || die "no nroffer set!?";
   
   # turn the switches into CLIs
@@ -88,7 +91,21 @@ sub parse_from_file {
    and print "About to run $command\n";
   ;
   
-  my $rslt = `$command`;
+  my $cache = $command;
+  $cache =~ tr/a-zA-Z0-9/_/cs;
+  $cache = "$ENV{HOME}/.perldoc/$cache";
+
+  my $rslt;
+  if (-f $cache and -M $cache < -M $file) {
+    local @ARGV = $cache; local $/ = undef;
+    $rslt = <>;
+  } else {
+    $rslt = `$command`;
+    unless ($file =~ m#/tmp/#) {
+      my $fh; open $fh, ">", $cache
+        and print $fh $rslt;
+    }
+  }
 
   my $err;
 

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-04-21 21:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-21 21:20 [sisyphus] perldoc cache Alexey Tourbin

ALT Linux Sisyphus discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/sisyphus/0 sisyphus/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 sisyphus sisyphus/ http://lore.altlinux.org/sisyphus \
		sisyphus@altlinux.ru sisyphus@altlinux.org sisyphus@lists.altlinux.org sisyphus@lists.altlinux.ru sisyphus@lists.altlinux.com sisyphus@linuxteam.iplabs.ru sisyphus@list.linux-os.ru
	public-inbox-index sisyphus

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.sisyphus


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git