batman-rails-flo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +29 -0
  3. data/Rakefile +2 -0
  4. data/lib/batman-rails-flo.rb +5 -0
  5. data/lib/batman_rails_flo/railtie.rb +9 -0
  6. data/lib/batman_rails_flo/tasks.rake +14 -0
  7. data/lib/batman_rails_flo/version.rb +3 -0
  8. data/vendor/assets/javascripts/batman_rails_flo/flo_server.js +67 -0
  9. data/vendor/assets/javascripts/batman_rails_flo/live_reload.js.coffee +129 -0
  10. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/CNAME +1 -0
  11. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/CONTRIBUTING.md +9 -0
  12. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/LICENSE +22 -0
  13. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/README +50 -0
  14. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/bin/cake +7 -0
  15. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/bin/coffee +7 -0
  16. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/browser.js +134 -0
  17. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/cake.js +112 -0
  18. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/coffee-script.js +335 -0
  19. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/command.js +569 -0
  20. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/grammar.js +631 -0
  21. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/helpers.js +252 -0
  22. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/index.js +11 -0
  23. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/lexer.js +926 -0
  24. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/nodes.js +3158 -0
  25. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/optparse.js +139 -0
  26. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/parser.js +724 -0
  27. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/register.js +66 -0
  28. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/repl.js +163 -0
  29. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/rewriter.js +475 -0
  30. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/scope.js +146 -0
  31. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/sourcemap.js +161 -0
  32. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/LICENSE +21 -0
  33. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/examples/pow.js +6 -0
  34. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/index.js +82 -0
  35. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/package.json +34 -0
  36. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/readme.markdown +63 -0
  37. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/chmod.js +38 -0
  38. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/clobber.js +37 -0
  39. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/mkdirp.js +28 -0
  40. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/perm.js +32 -0
  41. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/perm_sync.js +39 -0
  42. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/race.js +41 -0
  43. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/rel.js +32 -0
  44. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/return.js +25 -0
  45. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/return_sync.js +24 -0
  46. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/root.js +18 -0
  47. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/sync.js +32 -0
  48. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/umask.js +28 -0
  49. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/umask_sync.js +32 -0
  50. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/package.json +50 -0
  51. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/register.js +1 -0
  52. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/LICENSE +30 -0
  53. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/PATENTS +23 -0
  54. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/README.md +124 -0
  55. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/bin/flo +26 -0
  56. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/configure/configure.html +57 -0
  57. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/configure/configure.js +205 -0
  58. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/configure/style.css +334 -0
  59. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/connection.js +235 -0
  60. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/devtools.html +12 -0
  61. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/index.js +323 -0
  62. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/logger.js +42 -0
  63. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/logo.png +0 -0
  64. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/manifest.json +13 -0
  65. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/session.js +305 -0
  66. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/index.js +10 -0
  67. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/lib/flo.js +226 -0
  68. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/lib/server.js +94 -0
  69. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/README.md +66 -0
  70. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/index.js +437 -0
  71. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/LICENSE +23 -0
  72. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/README.md +218 -0
  73. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/minimatch.js +1055 -0
  74. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/CONTRIBUTORS +14 -0
  75. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/LICENSE +23 -0
  76. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/README.md +97 -0
  77. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/lib/lru-cache.js +252 -0
  78. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/package.json +33 -0
  79. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/test/basic.js +369 -0
  80. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/test/foreach.js +52 -0
  81. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/test/memory-leak.js +50 -0
  82. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/LICENSE +27 -0
  83. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/README.md +53 -0
  84. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/bench.js +283 -0
  85. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/package.json +42 -0
  86. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/sigmund.js +39 -0
  87. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/test/basic.js +24 -0
  88. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/package.json +40 -0
  89. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/basic.js +399 -0
  90. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/brace-expand.js +33 -0
  91. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/caching.js +14 -0
  92. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/defaults.js +274 -0
  93. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/extglob-ending-with-state-char.js +8 -0
  94. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/lib/walker.js +111 -0
  95. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/license +13 -0
  96. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/lib/makeerror.js +87 -0
  97. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/node_modules/tmpl/lib/tmpl.js +17 -0
  98. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/node_modules/tmpl/package.json +31 -0
  99. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/node_modules/tmpl/readme.md +10 -0
  100. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/package.json +34 -0
  101. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/readme.md +77 -0
  102. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/package.json +36 -0
  103. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/readme.md +52 -0
  104. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/LICENSE +55 -0
  105. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/main.js +128 -0
  106. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/package.json +34 -0
  107. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/readme.mkd +72 -0
  108. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/d/d/t +0 -0
  109. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/d/t +0 -0
  110. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/test_monitor.js +31 -0
  111. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/test_monitorRootDirectory.js +28 -0
  112. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/test_watchTree.js +20 -0
  113. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/package.json +45 -0
  114. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/test/test.js +243 -0
  115. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/CHANGELOG.md +81 -0
  116. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/LICENSE +177 -0
  117. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/Makefile +11 -0
  118. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/README.md +245 -0
  119. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/binding.gyp +14 -0
  120. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Makefile +355 -0
  121. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/linker.lock +0 -0
  122. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/obj.target/validation/src/validation.o +0 -0
  123. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/obj.target/xor/src/xor.o +0 -0
  124. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/validation.node +0 -0
  125. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/xor.node +0 -0
  126. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/binding.Makefile +6 -0
  127. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/config.gypi +115 -0
  128. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/gyp-mac-tool +512 -0
  129. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/validation.target.mk +154 -0
  130. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/xor.target.mk +154 -0
  131. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/index.js +1 -0
  132. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/install.js +31 -0
  133. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Constants.js +23 -0
  134. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Deprecation.js +38 -0
  135. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Validation.fallback.js +12 -0
  136. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Validation.js +18 -0
  137. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketClient.js +359 -0
  138. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketConnection.js +717 -0
  139. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketFrame.js +282 -0
  140. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketRequest.js +478 -0
  141. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketRouter.js +154 -0
  142. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketRouterRequest.js +59 -0
  143. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketServer.js +216 -0
  144. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/utils.js +7 -0
  145. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/websocket.js +11 -0
  146. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/xor.fallback.js +13 -0
  147. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/xor.js +18 -0
  148. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/package.json +43 -0
  149. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/src/validation.cc +144 -0
  150. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/src/xor.cpp +86 -0
  151. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/vendor/FastBufferList.js +192 -0
  152. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/vendor/node-ctype/LICENSE +18 -0
  153. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/vendor/node-ctype/ctio-faster.js +1126 -0
  154. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/package.json +25 -0
  155. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/browser_websocket.js +63 -0
  156. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/connection_test.js +57 -0
  157. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/logger_mock.js +15 -0
  158. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/session_test.js +194 -0
  159. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/server/flo_test.js +211 -0
  160. data/vendor/assets/javascripts/batman_rails_flo/package.json +15 -0
  161. data/vendor/assets/javascripts/batman_rails_flo/reload_event_handler.js.coffee +56 -0
  162. metadata +232 -0
@@ -0,0 +1,14 @@
1
+ # Authors, sorted by whether or not they are me
2
+ Isaac Z. Schlueter <i@izs.me>
3
+ Brian Cottingham <spiffytech@gmail.com>
4
+ Carlos Brito Lage <carlos@carloslage.net>
5
+ Jesse Dailey <jesse.dailey@gmail.com>
6
+ Kevin O'Hara <kevinohara80@gmail.com>
7
+ Marco Rogers <marco.rogers@gmail.com>
8
+ Mark Cavage <mcavage@gmail.com>
9
+ Marko Mikulicic <marko.mikulicic@isti.cnr.it>
10
+ Nathan Rajlich <nathan@tootallnate.net>
11
+ Satheesh Natesan <snateshan@myspace-inc.com>
12
+ Trent Mick <trentm@gmail.com>
13
+ ashleybrener <ashley@starlogik.com>
14
+ n4kz <n4kz@n4kz.com>
@@ -0,0 +1,23 @@
1
+ Copyright 2009, 2010, 2011 Isaac Z. Schlueter.
2
+ All rights reserved.
3
+
4
+ Permission is hereby granted, free of charge, to any person
5
+ obtaining a copy of this software and associated documentation
6
+ files (the "Software"), to deal in the Software without
7
+ restriction, including without limitation the rights to use,
8
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the
10
+ Software is furnished to do so, subject to the following
11
+ conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,97 @@
1
+ # lru cache
2
+
3
+ A cache object that deletes the least-recently-used items.
4
+
5
+ ## Usage:
6
+
7
+ ```javascript
8
+ var LRU = require("lru-cache")
9
+ , options = { max: 500
10
+ , length: function (n) { return n * 2 }
11
+ , dispose: function (key, n) { n.close() }
12
+ , maxAge: 1000 * 60 * 60 }
13
+ , cache = LRU(options)
14
+ , otherCache = LRU(50) // sets just the max size
15
+
16
+ cache.set("key", "value")
17
+ cache.get("key") // "value"
18
+
19
+ cache.reset() // empty the cache
20
+ ```
21
+
22
+ If you put more stuff in it, then items will fall out.
23
+
24
+ If you try to put an oversized thing in it, then it'll fall out right
25
+ away.
26
+
27
+ ## Options
28
+
29
+ * `max` The maximum size of the cache, checked by applying the length
30
+ function to all values in the cache. Not setting this is kind of
31
+ silly, since that's the whole purpose of this lib, but it defaults
32
+ to `Infinity`.
33
+ * `maxAge` Maximum age in ms. Items are not pro-actively pruned out
34
+ as they age, but if you try to get an item that is too old, it'll
35
+ drop it and return undefined instead of giving it to you.
36
+ * `length` Function that is used to calculate the length of stored
37
+ items. If you're storing strings or buffers, then you probably want
38
+ to do something like `function(n){return n.length}`. The default is
39
+ `function(n){return 1}`, which is fine if you want to store `n`
40
+ like-sized things.
41
+ * `dispose` Function that is called on items when they are dropped
42
+ from the cache. This can be handy if you want to close file
43
+ descriptors or do other cleanup tasks when items are no longer
44
+ accessible. Called with `key, value`. It's called *before*
45
+ actually removing the item from the internal cache, so if you want
46
+ to immediately put it back in, you'll have to do that in a
47
+ `nextTick` or `setTimeout` callback or it won't do anything.
48
+ * `stale` By default, if you set a `maxAge`, it'll only actually pull
49
+ stale items out of the cache when you `get(key)`. (That is, it's
50
+ not pre-emptively doing a `setTimeout` or anything.) If you set
51
+ `stale:true`, it'll return the stale value before deleting it. If
52
+ you don't set this, then it'll return `undefined` when you try to
53
+ get a stale entry, as if it had already been deleted.
54
+
55
+ ## API
56
+
57
+ * `set(key, value)`
58
+ * `get(key) => value`
59
+
60
+ Both of these will update the "recently used"-ness of the key.
61
+ They do what you think.
62
+
63
+ * `peek(key)`
64
+
65
+ Returns the key value (or `undefined` if not found) without
66
+ updating the "recently used"-ness of the key.
67
+
68
+ (If you find yourself using this a lot, you *might* be using the
69
+ wrong sort of data structure, but there are some use cases where
70
+ it's handy.)
71
+
72
+ * `del(key)`
73
+
74
+ Deletes a key out of the cache.
75
+
76
+ * `reset()`
77
+
78
+ Clear the cache entirely, throwing away all values.
79
+
80
+ * `has(key)`
81
+
82
+ Check if a key is in the cache, without updating the recent-ness
83
+ or deleting it for being stale.
84
+
85
+ * `forEach(function(value,key,cache), [thisp])`
86
+
87
+ Just like `Array.prototype.forEach`. Iterates over all the keys
88
+ in the cache, in order of recent-ness. (Ie, more recently used
89
+ items are iterated over first.)
90
+
91
+ * `keys()`
92
+
93
+ Return an array of the keys in the cache.
94
+
95
+ * `values()`
96
+
97
+ Return an array of the values in the cache.
@@ -0,0 +1,252 @@
1
+ ;(function () { // closure for web browsers
2
+
3
+ if (typeof module === 'object' && module.exports) {
4
+ module.exports = LRUCache
5
+ } else {
6
+ // just set the global for non-node platforms.
7
+ this.LRUCache = LRUCache
8
+ }
9
+
10
+ function hOP (obj, key) {
11
+ return Object.prototype.hasOwnProperty.call(obj, key)
12
+ }
13
+
14
+ function naiveLength () { return 1 }
15
+
16
+ function LRUCache (options) {
17
+ if (!(this instanceof LRUCache))
18
+ return new LRUCache(options)
19
+
20
+ if (typeof options === 'number')
21
+ options = { max: options }
22
+
23
+ if (!options)
24
+ options = {}
25
+
26
+ this._max = options.max
27
+ // Kind of weird to have a default max of Infinity, but oh well.
28
+ if (!this._max || !(typeof this._max === "number") || this._max <= 0 )
29
+ this._max = Infinity
30
+
31
+ this._lengthCalculator = options.length || naiveLength
32
+ if (typeof this._lengthCalculator !== "function")
33
+ this._lengthCalculator = naiveLength
34
+
35
+ this._allowStale = options.stale || false
36
+ this._maxAge = options.maxAge || null
37
+ this._dispose = options.dispose
38
+ this.reset()
39
+ }
40
+
41
+ // resize the cache when the max changes.
42
+ Object.defineProperty(LRUCache.prototype, "max",
43
+ { set : function (mL) {
44
+ if (!mL || !(typeof mL === "number") || mL <= 0 ) mL = Infinity
45
+ this._max = mL
46
+ if (this._length > this._max) trim(this)
47
+ }
48
+ , get : function () { return this._max }
49
+ , enumerable : true
50
+ })
51
+
52
+ // resize the cache when the lengthCalculator changes.
53
+ Object.defineProperty(LRUCache.prototype, "lengthCalculator",
54
+ { set : function (lC) {
55
+ if (typeof lC !== "function") {
56
+ this._lengthCalculator = naiveLength
57
+ this._length = this._itemCount
58
+ for (var key in this._cache) {
59
+ this._cache[key].length = 1
60
+ }
61
+ } else {
62
+ this._lengthCalculator = lC
63
+ this._length = 0
64
+ for (var key in this._cache) {
65
+ this._cache[key].length = this._lengthCalculator(this._cache[key].value)
66
+ this._length += this._cache[key].length
67
+ }
68
+ }
69
+
70
+ if (this._length > this._max) trim(this)
71
+ }
72
+ , get : function () { return this._lengthCalculator }
73
+ , enumerable : true
74
+ })
75
+
76
+ Object.defineProperty(LRUCache.prototype, "length",
77
+ { get : function () { return this._length }
78
+ , enumerable : true
79
+ })
80
+
81
+
82
+ Object.defineProperty(LRUCache.prototype, "itemCount",
83
+ { get : function () { return this._itemCount }
84
+ , enumerable : true
85
+ })
86
+
87
+ LRUCache.prototype.forEach = function (fn, thisp) {
88
+ thisp = thisp || this
89
+ var i = 0;
90
+ for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) {
91
+ i++
92
+ var hit = this._lruList[k]
93
+ if (this._maxAge && (Date.now() - hit.now > this._maxAge)) {
94
+ del(this, hit)
95
+ if (!this._allowStale) hit = undefined
96
+ }
97
+ if (hit) {
98
+ fn.call(thisp, hit.value, hit.key, this)
99
+ }
100
+ }
101
+ }
102
+
103
+ LRUCache.prototype.keys = function () {
104
+ var keys = new Array(this._itemCount)
105
+ var i = 0
106
+ for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) {
107
+ var hit = this._lruList[k]
108
+ keys[i++] = hit.key
109
+ }
110
+ return keys
111
+ }
112
+
113
+ LRUCache.prototype.values = function () {
114
+ var values = new Array(this._itemCount)
115
+ var i = 0
116
+ for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) {
117
+ var hit = this._lruList[k]
118
+ values[i++] = hit.value
119
+ }
120
+ return values
121
+ }
122
+
123
+ LRUCache.prototype.reset = function () {
124
+ if (this._dispose && this._cache) {
125
+ for (var k in this._cache) {
126
+ this._dispose(k, this._cache[k].value)
127
+ }
128
+ }
129
+
130
+ this._cache = Object.create(null) // hash of items by key
131
+ this._lruList = Object.create(null) // list of items in order of use recency
132
+ this._mru = 0 // most recently used
133
+ this._lru = 0 // least recently used
134
+ this._length = 0 // number of items in the list
135
+ this._itemCount = 0
136
+ }
137
+
138
+ // Provided for debugging/dev purposes only. No promises whatsoever that
139
+ // this API stays stable.
140
+ LRUCache.prototype.dump = function () {
141
+ return this._cache
142
+ }
143
+
144
+ LRUCache.prototype.dumpLru = function () {
145
+ return this._lruList
146
+ }
147
+
148
+ LRUCache.prototype.set = function (key, value) {
149
+ if (hOP(this._cache, key)) {
150
+ // dispose of the old one before overwriting
151
+ if (this._dispose) this._dispose(key, this._cache[key].value)
152
+ if (this._maxAge) this._cache[key].now = Date.now()
153
+ this._cache[key].value = value
154
+ this.get(key)
155
+ return true
156
+ }
157
+
158
+ var len = this._lengthCalculator(value)
159
+ var age = this._maxAge ? Date.now() : 0
160
+ var hit = new Entry(key, value, this._mru++, len, age)
161
+
162
+ // oversized objects fall out of cache automatically.
163
+ if (hit.length > this._max) {
164
+ if (this._dispose) this._dispose(key, value)
165
+ return false
166
+ }
167
+
168
+ this._length += hit.length
169
+ this._lruList[hit.lu] = this._cache[key] = hit
170
+ this._itemCount ++
171
+
172
+ if (this._length > this._max) trim(this)
173
+ return true
174
+ }
175
+
176
+ LRUCache.prototype.has = function (key) {
177
+ if (!hOP(this._cache, key)) return false
178
+ var hit = this._cache[key]
179
+ if (this._maxAge && (Date.now() - hit.now > this._maxAge)) {
180
+ return false
181
+ }
182
+ return true
183
+ }
184
+
185
+ LRUCache.prototype.get = function (key) {
186
+ return get(this, key, true)
187
+ }
188
+
189
+ LRUCache.prototype.peek = function (key) {
190
+ return get(this, key, false)
191
+ }
192
+
193
+ LRUCache.prototype.pop = function () {
194
+ var hit = this._lruList[this._lru]
195
+ del(this, hit)
196
+ return hit || null
197
+ }
198
+
199
+ LRUCache.prototype.del = function (key) {
200
+ del(this, this._cache[key])
201
+ }
202
+
203
+ function get (self, key, doUse) {
204
+ var hit = self._cache[key]
205
+ if (hit) {
206
+ if (self._maxAge && (Date.now() - hit.now > self._maxAge)) {
207
+ del(self, hit)
208
+ if (!self._allowStale) hit = undefined
209
+ } else {
210
+ if (doUse) use(self, hit)
211
+ }
212
+ if (hit) hit = hit.value
213
+ }
214
+ return hit
215
+ }
216
+
217
+ function use (self, hit) {
218
+ shiftLU(self, hit)
219
+ hit.lu = self._mru ++
220
+ self._lruList[hit.lu] = hit
221
+ }
222
+
223
+ function trim (self) {
224
+ while (self._lru < self._mru && self._length > self._max)
225
+ del(self, self._lruList[self._lru])
226
+ }
227
+
228
+ function shiftLU (self, hit) {
229
+ delete self._lruList[ hit.lu ]
230
+ while (self._lru < self._mru && !self._lruList[self._lru]) self._lru ++
231
+ }
232
+
233
+ function del (self, hit) {
234
+ if (hit) {
235
+ if (self._dispose) self._dispose(hit.key, hit.value)
236
+ self._length -= hit.length
237
+ self._itemCount --
238
+ delete self._cache[ hit.key ]
239
+ shiftLU(self, hit)
240
+ }
241
+ }
242
+
243
+ // classy, since V8 prefers predictable objects.
244
+ function Entry (key, value, lu, length, now) {
245
+ this.key = key
246
+ this.value = value
247
+ this.lu = lu
248
+ this.length = length
249
+ this.now = now
250
+ }
251
+
252
+ })()
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "lru-cache",
3
+ "description": "A cache object that deletes the least-recently-used items.",
4
+ "version": "2.5.0",
5
+ "author": {
6
+ "name": "Isaac Z. Schlueter",
7
+ "email": "i@izs.me"
8
+ },
9
+ "scripts": {
10
+ "test": "tap test --gc"
11
+ },
12
+ "main": "lib/lru-cache.js",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git://github.com/isaacs/node-lru-cache.git"
16
+ },
17
+ "devDependencies": {
18
+ "tap": "",
19
+ "weak": ""
20
+ },
21
+ "license": {
22
+ "type": "MIT",
23
+ "url": "http://github.com/isaacs/node-lru-cache/raw/master/LICENSE"
24
+ },
25
+ "readme": "# lru cache\n\nA cache object that deletes the least-recently-used items.\n\n## Usage:\n\n```javascript\nvar LRU = require(\"lru-cache\")\n , options = { max: 500\n , length: function (n) { return n * 2 }\n , dispose: function (key, n) { n.close() }\n , maxAge: 1000 * 60 * 60 }\n , cache = LRU(options)\n , otherCache = LRU(50) // sets just the max size\n\ncache.set(\"key\", \"value\")\ncache.get(\"key\") // \"value\"\n\ncache.reset() // empty the cache\n```\n\nIf you put more stuff in it, then items will fall out.\n\nIf you try to put an oversized thing in it, then it'll fall out right\naway.\n\n## Options\n\n* `max` The maximum size of the cache, checked by applying the length\n function to all values in the cache. Not setting this is kind of\n silly, since that's the whole purpose of this lib, but it defaults\n to `Infinity`.\n* `maxAge` Maximum age in ms. Items are not pro-actively pruned out\n as they age, but if you try to get an item that is too old, it'll\n drop it and return undefined instead of giving it to you.\n* `length` Function that is used to calculate the length of stored\n items. If you're storing strings or buffers, then you probably want\n to do something like `function(n){return n.length}`. The default is\n `function(n){return 1}`, which is fine if you want to store `n`\n like-sized things.\n* `dispose` Function that is called on items when they are dropped\n from the cache. This can be handy if you want to close file\n descriptors or do other cleanup tasks when items are no longer\n accessible. Called with `key, value`. It's called *before*\n actually removing the item from the internal cache, so if you want\n to immediately put it back in, you'll have to do that in a\n `nextTick` or `setTimeout` callback or it won't do anything.\n* `stale` By default, if you set a `maxAge`, it'll only actually pull\n stale items out of the cache when you `get(key)`. (That is, it's\n not pre-emptively doing a `setTimeout` or anything.) If you set\n `stale:true`, it'll return the stale value before deleting it. If\n you don't set this, then it'll return `undefined` when you try to\n get a stale entry, as if it had already been deleted.\n\n## API\n\n* `set(key, value)`\n* `get(key) => value`\n\n Both of these will update the \"recently used\"-ness of the key.\n They do what you think.\n\n* `peek(key)`\n\n Returns the key value (or `undefined` if not found) without\n updating the \"recently used\"-ness of the key.\n\n (If you find yourself using this a lot, you *might* be using the\n wrong sort of data structure, but there are some use cases where\n it's handy.)\n\n* `del(key)`\n\n Deletes a key out of the cache.\n\n* `reset()`\n\n Clear the cache entirely, throwing away all values.\n\n* `has(key)`\n\n Check if a key is in the cache, without updating the recent-ness\n or deleting it for being stale.\n\n* `forEach(function(value,key,cache), [thisp])`\n\n Just like `Array.prototype.forEach`. Iterates over all the keys\n in the cache, in order of recent-ness. (Ie, more recently used\n items are iterated over first.)\n\n* `keys()`\n\n Return an array of the keys in the cache.\n\n* `values()`\n\n Return an array of the values in the cache.\n",
26
+ "readmeFilename": "README.md",
27
+ "bugs": {
28
+ "url": "https://github.com/isaacs/node-lru-cache/issues"
29
+ },
30
+ "homepage": "https://github.com/isaacs/node-lru-cache",
31
+ "_id": "lru-cache@2.5.0",
32
+ "_from": "lru-cache@2"
33
+ }
@@ -0,0 +1,369 @@
1
+ var test = require("tap").test
2
+ , LRU = require("../")
3
+
4
+ test("basic", function (t) {
5
+ var cache = new LRU({max: 10})
6
+ cache.set("key", "value")
7
+ t.equal(cache.get("key"), "value")
8
+ t.equal(cache.get("nada"), undefined)
9
+ t.equal(cache.length, 1)
10
+ t.equal(cache.max, 10)
11
+ t.end()
12
+ })
13
+
14
+ test("least recently set", function (t) {
15
+ var cache = new LRU(2)
16
+ cache.set("a", "A")
17
+ cache.set("b", "B")
18
+ cache.set("c", "C")
19
+ t.equal(cache.get("c"), "C")
20
+ t.equal(cache.get("b"), "B")
21
+ t.equal(cache.get("a"), undefined)
22
+ t.end()
23
+ })
24
+
25
+ test("lru recently gotten", function (t) {
26
+ var cache = new LRU(2)
27
+ cache.set("a", "A")
28
+ cache.set("b", "B")
29
+ cache.get("a")
30
+ cache.set("c", "C")
31
+ t.equal(cache.get("c"), "C")
32
+ t.equal(cache.get("b"), undefined)
33
+ t.equal(cache.get("a"), "A")
34
+ t.end()
35
+ })
36
+
37
+ test("del", function (t) {
38
+ var cache = new LRU(2)
39
+ cache.set("a", "A")
40
+ cache.del("a")
41
+ t.equal(cache.get("a"), undefined)
42
+ t.end()
43
+ })
44
+
45
+ test("max", function (t) {
46
+ var cache = new LRU(3)
47
+
48
+ // test changing the max, verify that the LRU items get dropped.
49
+ cache.max = 100
50
+ for (var i = 0; i < 100; i ++) cache.set(i, i)
51
+ t.equal(cache.length, 100)
52
+ for (var i = 0; i < 100; i ++) {
53
+ t.equal(cache.get(i), i)
54
+ }
55
+ cache.max = 3
56
+ t.equal(cache.length, 3)
57
+ for (var i = 0; i < 97; i ++) {
58
+ t.equal(cache.get(i), undefined)
59
+ }
60
+ for (var i = 98; i < 100; i ++) {
61
+ t.equal(cache.get(i), i)
62
+ }
63
+
64
+ // now remove the max restriction, and try again.
65
+ cache.max = "hello"
66
+ for (var i = 0; i < 100; i ++) cache.set(i, i)
67
+ t.equal(cache.length, 100)
68
+ for (var i = 0; i < 100; i ++) {
69
+ t.equal(cache.get(i), i)
70
+ }
71
+ // should trigger an immediate resize
72
+ cache.max = 3
73
+ t.equal(cache.length, 3)
74
+ for (var i = 0; i < 97; i ++) {
75
+ t.equal(cache.get(i), undefined)
76
+ }
77
+ for (var i = 98; i < 100; i ++) {
78
+ t.equal(cache.get(i), i)
79
+ }
80
+ t.end()
81
+ })
82
+
83
+ test("reset", function (t) {
84
+ var cache = new LRU(10)
85
+ cache.set("a", "A")
86
+ cache.set("b", "B")
87
+ cache.reset()
88
+ t.equal(cache.length, 0)
89
+ t.equal(cache.max, 10)
90
+ t.equal(cache.get("a"), undefined)
91
+ t.equal(cache.get("b"), undefined)
92
+ t.end()
93
+ })
94
+
95
+
96
+ // Note: `<cache>.dump()` is a debugging tool only. No guarantees are made
97
+ // about the format/layout of the response.
98
+ test("dump", function (t) {
99
+ var cache = new LRU(10)
100
+ var d = cache.dump();
101
+ t.equal(Object.keys(d).length, 0, "nothing in dump for empty cache")
102
+ cache.set("a", "A")
103
+ var d = cache.dump() // { a: { key: "a", value: "A", lu: 0 } }
104
+ t.ok(d.a)
105
+ t.equal(d.a.key, "a")
106
+ t.equal(d.a.value, "A")
107
+ t.equal(d.a.lu, 0)
108
+
109
+ cache.set("b", "B")
110
+ cache.get("b")
111
+ d = cache.dump()
112
+ t.ok(d.b)
113
+ t.equal(d.b.key, "b")
114
+ t.equal(d.b.value, "B")
115
+ t.equal(d.b.lu, 2)
116
+
117
+ t.end()
118
+ })
119
+
120
+
121
+ test("basic with weighed length", function (t) {
122
+ var cache = new LRU({
123
+ max: 100,
124
+ length: function (item) { return item.size }
125
+ })
126
+ cache.set("key", {val: "value", size: 50})
127
+ t.equal(cache.get("key").val, "value")
128
+ t.equal(cache.get("nada"), undefined)
129
+ t.equal(cache.lengthCalculator(cache.get("key")), 50)
130
+ t.equal(cache.length, 50)
131
+ t.equal(cache.max, 100)
132
+ t.end()
133
+ })
134
+
135
+
136
+ test("weighed length item too large", function (t) {
137
+ var cache = new LRU({
138
+ max: 10,
139
+ length: function (item) { return item.size }
140
+ })
141
+ t.equal(cache.max, 10)
142
+
143
+ // should fall out immediately
144
+ cache.set("key", {val: "value", size: 50})
145
+
146
+ t.equal(cache.length, 0)
147
+ t.equal(cache.get("key"), undefined)
148
+ t.end()
149
+ })
150
+
151
+ test("least recently set with weighed length", function (t) {
152
+ var cache = new LRU({
153
+ max:8,
154
+ length: function (item) { return item.length }
155
+ })
156
+ cache.set("a", "A")
157
+ cache.set("b", "BB")
158
+ cache.set("c", "CCC")
159
+ cache.set("d", "DDDD")
160
+ t.equal(cache.get("d"), "DDDD")
161
+ t.equal(cache.get("c"), "CCC")
162
+ t.equal(cache.get("b"), undefined)
163
+ t.equal(cache.get("a"), undefined)
164
+ t.end()
165
+ })
166
+
167
+ test("lru recently gotten with weighed length", function (t) {
168
+ var cache = new LRU({
169
+ max: 8,
170
+ length: function (item) { return item.length }
171
+ })
172
+ cache.set("a", "A")
173
+ cache.set("b", "BB")
174
+ cache.set("c", "CCC")
175
+ cache.get("a")
176
+ cache.get("b")
177
+ cache.set("d", "DDDD")
178
+ t.equal(cache.get("c"), undefined)
179
+ t.equal(cache.get("d"), "DDDD")
180
+ t.equal(cache.get("b"), "BB")
181
+ t.equal(cache.get("a"), "A")
182
+ t.end()
183
+ })
184
+
185
+ test("set returns proper booleans", function(t) {
186
+ var cache = new LRU({
187
+ max: 5,
188
+ length: function (item) { return item.length }
189
+ })
190
+
191
+ t.equal(cache.set("a", "A"), true)
192
+
193
+ // should return false for max exceeded
194
+ t.equal(cache.set("b", "donuts"), false)
195
+
196
+ t.equal(cache.set("b", "B"), true)
197
+ t.equal(cache.set("c", "CCCC"), true)
198
+ t.end()
199
+ })
200
+
201
+ test("drop the old items", function(t) {
202
+ var cache = new LRU({
203
+ max: 5,
204
+ maxAge: 50
205
+ })
206
+
207
+ cache.set("a", "A")
208
+
209
+ setTimeout(function () {
210
+ cache.set("b", "b")
211
+ t.equal(cache.get("a"), "A")
212
+ }, 25)
213
+
214
+ setTimeout(function () {
215
+ cache.set("c", "C")
216
+ // timed out
217
+ t.notOk(cache.get("a"))
218
+ }, 60)
219
+
220
+ setTimeout(function () {
221
+ t.notOk(cache.get("b"))
222
+ t.equal(cache.get("c"), "C")
223
+ }, 90)
224
+
225
+ setTimeout(function () {
226
+ t.notOk(cache.get("c"))
227
+ t.end()
228
+ }, 155)
229
+ })
230
+
231
+ test("disposal function", function(t) {
232
+ var disposed = false
233
+ var cache = new LRU({
234
+ max: 1,
235
+ dispose: function (k, n) {
236
+ disposed = n
237
+ }
238
+ })
239
+
240
+ cache.set(1, 1)
241
+ cache.set(2, 2)
242
+ t.equal(disposed, 1)
243
+ cache.set(3, 3)
244
+ t.equal(disposed, 2)
245
+ cache.reset()
246
+ t.equal(disposed, 3)
247
+ t.end()
248
+ })
249
+
250
+ test("disposal function on too big of item", function(t) {
251
+ var disposed = false
252
+ var cache = new LRU({
253
+ max: 1,
254
+ length: function (k) {
255
+ return k.length
256
+ },
257
+ dispose: function (k, n) {
258
+ disposed = n
259
+ }
260
+ })
261
+ var obj = [ 1, 2 ]
262
+
263
+ t.equal(disposed, false)
264
+ cache.set("obj", obj)
265
+ t.equal(disposed, obj)
266
+ t.end()
267
+ })
268
+
269
+ test("has()", function(t) {
270
+ var cache = new LRU({
271
+ max: 1,
272
+ maxAge: 10
273
+ })
274
+
275
+ cache.set('foo', 'bar')
276
+ t.equal(cache.has('foo'), true)
277
+ cache.set('blu', 'baz')
278
+ t.equal(cache.has('foo'), false)
279
+ t.equal(cache.has('blu'), true)
280
+ setTimeout(function() {
281
+ t.equal(cache.has('blu'), false)
282
+ t.end()
283
+ }, 15)
284
+ })
285
+
286
+ test("stale", function(t) {
287
+ var cache = new LRU({
288
+ maxAge: 10,
289
+ stale: true
290
+ })
291
+
292
+ cache.set('foo', 'bar')
293
+ t.equal(cache.get('foo'), 'bar')
294
+ t.equal(cache.has('foo'), true)
295
+ setTimeout(function() {
296
+ t.equal(cache.has('foo'), false)
297
+ t.equal(cache.get('foo'), 'bar')
298
+ t.equal(cache.get('foo'), undefined)
299
+ t.end()
300
+ }, 15)
301
+ })
302
+
303
+ test("lru update via set", function(t) {
304
+ var cache = LRU({ max: 2 });
305
+
306
+ cache.set('foo', 1);
307
+ cache.set('bar', 2);
308
+ cache.del('bar');
309
+ cache.set('baz', 3);
310
+ cache.set('qux', 4);
311
+
312
+ t.equal(cache.get('foo'), undefined)
313
+ t.equal(cache.get('bar'), undefined)
314
+ t.equal(cache.get('baz'), 3)
315
+ t.equal(cache.get('qux'), 4)
316
+ t.end()
317
+ })
318
+
319
+ test("least recently set w/ peek", function (t) {
320
+ var cache = new LRU(2)
321
+ cache.set("a", "A")
322
+ cache.set("b", "B")
323
+ t.equal(cache.peek("a"), "A")
324
+ cache.set("c", "C")
325
+ t.equal(cache.get("c"), "C")
326
+ t.equal(cache.get("b"), "B")
327
+ t.equal(cache.get("a"), undefined)
328
+ t.end()
329
+ })
330
+
331
+ test("pop the least used item", function (t) {
332
+ var cache = new LRU(3)
333
+ , last
334
+
335
+ cache.set("a", "A")
336
+ cache.set("b", "B")
337
+ cache.set("c", "C")
338
+
339
+ t.equal(cache.length, 3)
340
+ t.equal(cache.max, 3)
341
+
342
+ // Ensure we pop a, c, b
343
+ cache.get("b", "B")
344
+
345
+ last = cache.pop()
346
+ t.equal(last.key, "a")
347
+ t.equal(last.value, "A")
348
+ t.equal(cache.length, 2)
349
+ t.equal(cache.max, 3)
350
+
351
+ last = cache.pop()
352
+ t.equal(last.key, "c")
353
+ t.equal(last.value, "C")
354
+ t.equal(cache.length, 1)
355
+ t.equal(cache.max, 3)
356
+
357
+ last = cache.pop()
358
+ t.equal(last.key, "b")
359
+ t.equal(last.value, "B")
360
+ t.equal(cache.length, 0)
361
+ t.equal(cache.max, 3)
362
+
363
+ last = cache.pop()
364
+ t.equal(last, null)
365
+ t.equal(cache.length, 0)
366
+ t.equal(cache.max, 3)
367
+
368
+ t.end()
369
+ })