项目作者: scmorrison

项目描述 :
Perl 6 web-framework-neutral LRU caching module
高级语言: Perl 6
项目地址: git://github.com/scmorrison/perl6-Web-Cache.git
创建时间: 2017-03-10T05:52:19Z
项目社区:https://github.com/scmorrison/perl6-Web-Cache

开源协议:Artistic License 2.0

下载


Web::Cache Build Status

Web::Cache is a Perl 6 web framework independant LRU caching module.

The goal of this module is to provide a variety of cache backend wrappers and utilities that simplify caching tasks within the context of a web application.

note: this is very much a work in progress. Ideas, issues, and pull-requests welcome.

Usage

  1. # Bailador example
  2. use v6;
  3. use Bailador;
  4. use Web::Cache;
  5. Bailador::import; # for the template to work
  6. # Create a new cache store
  7. my &memory-cache = cache-create-store( size => 2048,
  8. backend => 'memory' );
  9. # TODO: Create multiple cache stores using different
  10. # backends. This will enable caching certain
  11. # content to different stores.
  12. # Cached templates!
  13. get / ^ '/template/' (.+) $ / => sub ($x) {
  14. my $template = 'tmpl.tt';
  15. my %params = %{ name => $x };
  16. my $fancy_cache_key = [$template, $x].join('-');
  17. # Any callback passed will be run on initial
  18. # cache insert only. Once cache expiration is
  19. # supported, this code will re-run again when
  20. # the key expires.
  21. memory-cache(key => $fancy_cache_key, {
  22. template($template, %params)
  23. });
  24. }
  25. #
  26. # Remove a key
  27. # memory-cache( key => $fancy_cache_key, :remove );
  28. #
  29. # Empty / clear cache
  30. # memory-cache( :clear );
  31. #
  32. baile;

Config

Currently only memory caching is supported.

  1. # Create cache store
  2. my &memory-cache = create-cache-store( size => 2048,
  3. backend => 'memory' );

Todo:

  1. my &memory-cache = create-cache-store( size => 2048,
  2. expires => 3600, # add expires parameter
  3. backend => 'memory' );
  4. my &disk-cache = create-cache-store( path => '/tmp/webcache/',
  5. expires => 3600,
  6. backend => 'disk' );
  7. my &memcached = create-cache-store( servers => ["127.0.0.1:11211"],
  8. expires => 3600,
  9. backend => 'memcached' );
  10. my &redis = create-cache-store( host => "127.0.0.1",
  11. port => 6379,
  12. expires => 3600,
  13. backend => 'redis' );

Installation

zef

  1. zef install Web::Cache

Manual

  1. git clone https://github.com/scmorrison/perl6-Web-Cache.git
  2. cd perl6-Web-Cache/
  3. zef install .

Todo

  • Support additional backends (disk, Memcached, Redis)
  • Cache key generator
  • Partial / fragment support
  • Tests

Requirements

AUTHORS

  • Sam Morrison

Copyright and license

Copyright 2017 Sam Morrison

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.