如何在perl脚本中缓存输出HTML?
是否有可用于缓存输出html的Perl类? 数据库不需要在每次访问页面时执行大型SQL查询 我发现了许多php类和函数用于缓存,但在Perl中并没有太多的例子 我正在Perl中查找这种类型的缓存 请提供如何使用Perl的详细信息如何在perl脚本中缓存输出HTML?,perl,caching,http-caching,Perl,Caching,Http Caching,是否有可用于缓存输出html的Perl类? 数据库不需要在每次访问页面时执行大型SQL查询 我发现了许多php类和函数用于缓存,但在Perl中并没有太多的例子 我正在Perl中查找这种类型的缓存 请提供如何使用Perl的详细信息 谢谢下面是一个简短的例子。重要的是,您需要对请求的url执行一些检查。例如,url是小写的,protocoll在url前面,诸如此类。所有可能杀死你的md5的东西。这只是一个真正简单的缓存方法。但它应该起作用: 未经测试 编辑: 我忘了说,您需要在else块中编写md5
谢谢下面是一个简短的例子。重要的是,您需要对请求的url执行一些检查。例如,url是小写的,protocoll在url前面,诸如此类。所有可能杀死你的md5的东西。这只是一个真正简单的缓存方法。但它应该起作用: 未经测试 编辑:
我忘了说,您需要在else块中编写md5缓存文件,使用生成url的md5。在以md5作为文件名的目录中保护页面,并在输入正常代码之前检查目录中的md5。这是一种非常简单的缓存方法。@Paulchenkiller如果可能的话,你能举个例子吗?我是一名学生,对perl不太在行
http://codecanyon.net/item/autocache/1734137
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use File::Slurp;
my $html = q{};
my $directory_to_md5 = 'directoy/to/md5sums/';
# this md5 comes from the requested url e.g.:
# its important, that the requested url is raw. you need to specify how it looks. for example, that the protocoll is always there.
# just implement a few checks
my $url_md5 = md5_hex('http://my-domain.com/test/call/etc');
# $url_md5 = 31330e57928d52c381e83355ea9e2aa5
if (-f $directory_to_md5 . $url_md5 ) {
# read_file comes from File::Slurp
# take a look further look at
# http://p3rl.org/File::Slurp
$html = read_file($directory_to_md5 . $url_md5);
} else {
# the real code goes here
# ...
$html = q{..}; # do stuff here.
# write_file comes from File::Slurp as well
write_file($directory_to_md5 . $url_md5, $html);
}