Skip to content
Newer
Older
100644 75 lines (56 sloc) 1.86 KB
0466a70 @aheckmann release 0.0.1
authored Jan 20, 2012
1 #Mongoose-TTL Plugin
2
c9061a1 @aheckmann guille
authored Jan 24, 2012
3 Provides time-to-live support for [Mongoose](http://mongoosejs.com).
0466a70 @aheckmann release 0.0.1
authored Jan 20, 2012
4
fc694c6 @aheckmann build status again afad
authored Jan 26, 2012
5 [![Build Status](https://secure.travis-ci.org/aheckmann/mongoose-ttl.png)](http://travis-ci.org/aheckmann/mongoose-ttl)
2cf2b1a @aheckmann build status
authored Jan 26, 2012
6
0466a70 @aheckmann release 0.0.1
authored Jan 20, 2012
7 Options:
8
9 - ttl: the time each doc should live in the db (default 60 seconds)
10 - interval: how often the expired doc reaper runs (default 5 mins)
11 - reap: enable the expired doc reaper (default true)
12 - onReap: callback passed to reaper execution
13
14 Example:
15
16 ```js
17 var schema = new Schema({..});
18 schema.plugin(ttl, { ttl: 5000 });
19 ```
20
c9061a1 @aheckmann guille
authored Jan 25, 2012
21 The ttl option supports the ms module by [guille](https://github.com/guille) meaning
0466a70 @aheckmann release 0.0.1
authored Jan 20, 2012
22 we can specify ttls with friendlier syntax. Example:
23
24 ```
25 value milliseconds
26 ========================
27 '2d' 172800000
28 '1.5h' 5400000
29 '1h' 3600000
30 '1m' 60000
31 '5s' 5000
32 '500ms' 500
33 100 100
34 ```
35
36 The expired document reaper can be disabled by passing `reap: false`.
37 Useful when working in multi-core environments when we only want one
38 process executing it.
39
1c68104 @aheckmann readme
authored Jan 24, 2012
40 ```js
0466a70 @aheckmann release 0.0.1
authored Jan 20, 2012
41 var schema = new Schema({..});
42 schema.plugin(ttl, { ttl: 5000, reap: false });
43 var Cache = db.model('Cache', schema);
44 if (isMyWorker) Cache.startTTLReaper();
45 ```
46
47 The reaper can also be stopped.
48
49 ```js
50 Cache.stopTTLReaper();
51 ```
52
53 Time-to-live is specified at the collection level, however
54 it can also be overridden for a given document.
55
56 ```js
57 var cache = new Cache;
58 cache.ttl = '2m' // lives for two minutes
59 cache.save();
60 ```
61
62 We can also reset the ttl for a given document to its
63 default plugin state.
64
65 ```js
66 cache.resetTTL();
67 ```
add3eed @aheckmann release 0.0.2
authored Jan 28, 2012
68 ## Mongoose Version
69 >= 2.5.2
0466a70 @aheckmann release 0.0.1
authored Jan 20, 2012
70
39e2dab @aheckmann add note about first class mongodb ttl collections.
authored May 11, 2012
71 ### MongoDB TTL collections
72 MongoDB is getting official support for TTL collections [soon-ish](https://github.com/mongodb/mongo/commit/25bdc679a0e559d64ec7f22b0468cf5b1671c4e7) at which point this plugin will need to change.
73
add3eed @aheckmann release 0.0.2
authored Jan 28, 2012
74 [LICENCE](https://github.com/aheckmann/mongoose-ttl/blob/master/LICENSE)
Something went wrong with that request. Please try again.