GithubHelp home page GithubHelp logo

nvdnkpr / mongoose-ttl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mongoosejs/mongoose-ttl

0.0 2.0 0.0 91 KB

Provides time-to-live support for Mongoose

Home Page: http://aheckmann.github.com/mongoose-ttl

License: MIT License

mongoose-ttl's Introduction

#Mongoose-TTL Plugin

Provides time-to-live support for Mongoose.

Build Status

Options:

  • ttl: the time each doc should live in the db (default 60 seconds)
  • interval: how often the expired doc reaper runs (default 5 mins)
  • reap: enable the expired doc reaper (default true)
  • onReap: callback passed to reaper execution

Example:

var schema = new Schema({..});
schema.plugin(ttl, { ttl: 5000 });

The ttl option supports the ms module by guille meaning we can specify ttls with friendlier syntax. Example:

 value     milliseconds
========================
 '2d'      172800000
 '1.5h'    5400000
 '1h'      3600000
 '1m'      60000
 '5s'      5000
 '500ms'   500
 100       100

The expired document reaper can be disabled by passing reap: false. Useful when working in multi-core environments when we only want one process executing it.

var schema = new Schema({..});
schema.plugin(ttl, { ttl: 5000, reap: false });
var Cache = db.model('Cache', schema);
if (isMyWorker) Cache.startTTLReaper();

The reaper can also be stopped.

Cache.stopTTLReaper();

Time-to-live is specified at the collection level, however it can also be overridden for a given document.

var cache = new Cache;
cache.ttl = '2m' // lives for two minutes
cache.save();

We can also reset the ttl for a given document to its default plugin state.

cache.resetTTL();

Mongoose Version

= 2.5.2

MongoDB TTL collections

MongoDB >= 2.2 has official support for TTL collections. The official feature is not quite as flexible as this plugin but offers alternative benefits a plugin cannot. Consider reading the docs and making an informed choice.

LICENSE

mongoose-ttl's People

Contributors

aheckmann avatar

Watchers

Navid Nikpour 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.