Giter Site home page Giter Site logo

mojolicious-plugin-chi's Introduction

NAME

Mojolicious::Plugin::CHI - Use CHI caches within Mojolicious

SYNOPSIS

# Mojolicious
$app->plugin(CHI => {
  MyCache => {
    driver     => 'FastMmap',
    root_dir   => '/cache',
    cache_size => '20m'
  }
});

# Mojolicious::Lite
plugin 'CHI' => {
  default => {
    driver => 'Memory',
    global => 1
  }
};

# In Controllers:
$c->chi('MyCache')->set(my_key => 'This is my value');
print $c->chi('MyCache')->get('my_key');

# Using the default cache
$c->chi->set(from_memory => 'With love!');
print $c->chi->get('from_memory');

DESCRIPTION

Mojolicious::Plugin::CHI is a simple plugin to work with CHI caches within Mojolicious.

METHODS

register

# Mojolicious
$app->plugin(CHI => {
  MyCache => {
    driver     => 'FastMmap',
    root_dir   => '/cache',
    cache_size => '20m'
  },
  default => {
    driver => 'Memory',
    global => 1
  },
  namespaces => 1
});

# Mojolicious::Lite
plugin 'CHI' => {
  default => { driver => 'Memory', global => 1 }
};

# Or in your config file
{
  CHI => {
    default => {
      driver => 'Memory',
      global => 1
    }
  }
}

Called when registering the plugin. On creation, the plugin accepts a hash of cache names associated with CHI objects.

In addition to that, you can set the namespaces parameter to a true value. In this case, the cache handle name will also be set as the namespace of the CHI object.

All parameters can be set either on registration or as part of the configuration file with the key CHI.

Note: By default, the namespaces flag is deactivated and you have to set the namespace of your cache manually. This will change in further releases.

HELPERS

chi

# In Controllers:
$c->chi('MyCache')->set(my_key => 'This is my value', '10 min');
print $c->chi('MyCache')->get('my_key');
print $c->chi->get('from_default_cache');

Returns a CHI handle if registered. Accepts the name of the registered cache. If no cache handle name is given, a cache handle name default is assumed.

DEPENDENCIES

Mojolicious, CHI.

Note: CHI has a lot of dependencies. It is thus not recommended to use this plugin in a CGI environment.

CONTRIBUTORS

Boris Däppen (borisdaeppen)

AVAILABILITY

https://github.com/Akron/Mojolicious-Plugin-CHI

COPYRIGHT AND LICENSE

Copyright (C) 2012, Nils Diewald.

This program is free software, you can redistribute it and/or modify it under the same terms as Perl.

mojolicious-plugin-chi's People

Contributors

akron avatar borisdaeppen avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.