├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .travis.yml ├── .verb.md ├── LICENSE ├── README.md ├── examples.js ├── gulpfile.js ├── index.js ├── package.json └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | charset = utf-8 7 | indent_size = 2 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [{**/{actual,fixtures,expected,templates}/**,*.md}] 12 | trim_trailing_whitespace = false 13 | insert_final_newline = false -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "ecmaFeatures": { 3 | "modules": true, 4 | "experimentalObjectRestSpread": true 5 | }, 6 | 7 | "env": { 8 | "browser": false, 9 | "es6": true, 10 | "node": true, 11 | "mocha": true 12 | }, 13 | 14 | "globals": { 15 | "document": false, 16 | "navigator": false, 17 | "window": false 18 | }, 19 | 20 | "rules": { 21 | "accessor-pairs": 2, 22 | "arrow-spacing": [2, { "before": true, "after": true }], 23 | "block-spacing": [2, "always"], 24 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 25 | "comma-dangle": [2, "never"], 26 | "comma-spacing": [2, { "before": false, "after": true }], 27 | "comma-style": [2, "last"], 28 | "constructor-super": 2, 29 | "curly": [2, "multi-line"], 30 | "dot-location": [2, "property"], 31 | "eol-last": 2, 32 | "eqeqeq": [2, "allow-null"], 33 | "generator-star-spacing": [2, { "before": true, "after": true }], 34 | "handle-callback-err": [2, "^(err|error)$" ], 35 | "indent": [2, 2, { "SwitchCase": 1 }], 36 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 37 | "keyword-spacing": [2, { "before": true, "after": true }], 38 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 39 | "new-parens": 2, 40 | "no-array-constructor": 2, 41 | "no-caller": 2, 42 | "no-class-assign": 2, 43 | "no-cond-assign": 2, 44 | "no-const-assign": 2, 45 | "no-control-regex": 2, 46 | "no-debugger": 2, 47 | "no-delete-var": 2, 48 | "no-dupe-args": 2, 49 | "no-dupe-class-members": 2, 50 | "no-dupe-keys": 2, 51 | "no-duplicate-case": 2, 52 | "no-empty-character-class": 2, 53 | "no-eval": 2, 54 | "no-ex-assign": 2, 55 | "no-extend-native": 2, 56 | "no-extra-bind": 2, 57 | "no-extra-boolean-cast": 2, 58 | "no-extra-parens": [2, "functions"], 59 | "no-fallthrough": 2, 60 | "no-floating-decimal": 2, 61 | "no-func-assign": 2, 62 | "no-implied-eval": 2, 63 | "no-inner-declarations": [2, "functions"], 64 | "no-invalid-regexp": 2, 65 | "no-irregular-whitespace": 2, 66 | "no-iterator": 2, 67 | "no-label-var": 2, 68 | "no-labels": 2, 69 | "no-lone-blocks": 2, 70 | "no-mixed-spaces-and-tabs": 2, 71 | "no-multi-spaces": 2, 72 | "no-multi-str": 2, 73 | "no-multiple-empty-lines": [2, { "max": 1 }], 74 | "no-native-reassign": 0, 75 | "no-negated-in-lhs": 2, 76 | "no-new": 2, 77 | "no-new-func": 2, 78 | "no-new-object": 2, 79 | "no-new-require": 2, 80 | "no-new-wrappers": 2, 81 | "no-obj-calls": 2, 82 | "no-octal": 2, 83 | "no-octal-escape": 2, 84 | "no-proto": 0, 85 | "no-redeclare": 2, 86 | "no-regex-spaces": 2, 87 | "no-return-assign": 2, 88 | "no-self-compare": 2, 89 | "no-sequences": 2, 90 | "no-shadow-restricted-names": 2, 91 | "no-spaced-func": 2, 92 | "no-sparse-arrays": 2, 93 | "no-this-before-super": 2, 94 | "no-throw-literal": 2, 95 | "no-trailing-spaces": 0, 96 | "no-undef": 2, 97 | "no-undef-init": 2, 98 | "no-unexpected-multiline": 2, 99 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 100 | "no-unreachable": 2, 101 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 102 | "no-useless-call": 0, 103 | "no-with": 2, 104 | "one-var": [0, { "initialized": "never" }], 105 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], 106 | "padded-blocks": [0, "never"], 107 | "quotes": [2, "single", "avoid-escape"], 108 | "radix": 2, 109 | "semi": [2, "always"], 110 | "semi-spacing": [2, { "before": false, "after": true }], 111 | "space-before-blocks": [2, "always"], 112 | "space-before-function-paren": [2, "never"], 113 | "space-in-parens": [2, "never"], 114 | "space-infix-ops": 2, 115 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 116 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], 117 | "use-isnan": 2, 118 | "valid-typeof": 2, 119 | "wrap-iife": [2, "any"], 120 | "yoda": [2, "never"] 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # always ignore files 2 | *.DS_Store 3 | *.sublime-* 4 | 5 | # test related, or directories generated by tests 6 | test/actual 7 | actual 8 | coverage 9 | .nyc* 10 | 11 | # npm 12 | node_modules 13 | npm-debug.log 14 | 15 | # yarn 16 | yarn.lock 17 | yarn-error.log 18 | 19 | # misc 20 | _gh_pages 21 | _draft 22 | _drafts 23 | bower_components 24 | vendor 25 | temp 26 | tmp 27 | TODO.md 28 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - node 5 | - '7' 6 | - '6' 7 | - '5' 8 | - '4' 9 | - '0.12' 10 | - '0.10' 11 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | ## Usage 2 | 3 | ```js 4 | var Fragment = require('{%= name %}'); 5 | var fragment = new Fragment(); 6 | ``` 7 | 8 | ## API 9 | {%= apidocs("index.js") %} 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2017, Jon Schlinkert 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fragment-cache [![NPM version](https://img.shields.io/npm/v/fragment-cache.svg?style=flat)](https://www.npmjs.com/package/fragment-cache) [![NPM downloads](https://img.shields.io/npm/dm/fragment-cache.svg?style=flat)](https://npmjs.org/package/fragment-cache) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/fragment-cache.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/fragment-cache) 2 | 3 | > A cache for managing namespaced sub-caches 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | ```sh 10 | $ npm install --save fragment-cache 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```js 16 | var Fragment = require('fragment-cache'); 17 | var fragment = new Fragment(); 18 | ``` 19 | 20 | ## API 21 | 22 | ### [FragmentCache](index.js#L24) 23 | 24 | Create a new `FragmentCache` with an optional object to use for `caches`. 25 | 26 | **Example** 27 | 28 | ```js 29 | var fragment = new FragmentCache(); 30 | ``` 31 | 32 | **Params** 33 | 34 | * `cacheName` **{String}** 35 | * `returns` **{Object}**: Returns the [map-cache](https://github.com/jonschlinkert/map-cache) instance. 36 | 37 | ### [.cache](index.js#L49) 38 | 39 | Get cache `name` from the `fragment.caches` object. Creates a new `MapCache` if it doesn't already exist. 40 | 41 | **Example** 42 | 43 | ```js 44 | var cache = fragment.cache('files'); 45 | console.log(fragment.caches.hasOwnProperty('files')); 46 | //=> true 47 | ``` 48 | 49 | **Params** 50 | 51 | * `cacheName` **{String}** 52 | * `returns` **{Object}**: Returns the [map-cache](https://github.com/jonschlinkert/map-cache) instance. 53 | 54 | ### [.set](index.js#L67) 55 | 56 | Set a value for property `key` on cache `name` 57 | 58 | **Example** 59 | 60 | ```js 61 | fragment.set('files', 'somefile.js', new File({path: 'somefile.js'})); 62 | ``` 63 | 64 | **Params** 65 | 66 | * `name` **{String}** 67 | * `key` **{String}**: Property name to set 68 | * `val` **{any}**: The value of `key` 69 | * `returns` **{Object}**: The cache instance for chaining 70 | 71 | ### [.has](index.js#L93) 72 | 73 | Returns true if a non-undefined value is set for `key` on fragment cache `name`. 74 | 75 | **Example** 76 | 77 | ```js 78 | var cache = fragment.cache('files'); 79 | cache.set('somefile.js'); 80 | 81 | console.log(cache.has('somefile.js')); 82 | //=> true 83 | 84 | console.log(cache.has('some-other-file.js')); 85 | //=> false 86 | ``` 87 | 88 | **Params** 89 | 90 | * `name` **{String}**: Cache name 91 | * `key` **{String}**: Optionally specify a property to check for on cache `name` 92 | * `returns` **{Boolean}** 93 | 94 | ### [.get](index.js#L115) 95 | 96 | Get `name`, or if specified, the value of `key`. Invokes the [cache](#cache) method, so that cache `name` will be created it doesn't already exist. If `key` is not passed, the entire cache (`name`) is returned. 97 | 98 | **Example** 99 | 100 | ```js 101 | var Vinyl = require('vinyl'); 102 | var cache = fragment.cache('files'); 103 | cache.set('somefile.js', new Vinyl({path: 'somefile.js'})); 104 | console.log(cache.get('somefile.js')); 105 | //=> 106 | ``` 107 | 108 | **Params** 109 | 110 | * `name` **{String}** 111 | * `returns` **{Object}**: Returns cache `name`, or the value of `key` if specified 112 | 113 | ## About 114 | 115 | ### Related projects 116 | 117 | * [base](https://www.npmjs.com/package/base): base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… [more](https://github.com/node-base/base) | [homepage](https://github.com/node-base/base "base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting with a handful of common methods, like `set`, `get`, `del` and `use`.") 118 | * [map-cache](https://www.npmjs.com/package/map-cache): Basic cache object for storing key-value pairs. | [homepage](https://github.com/jonschlinkert/map-cache "Basic cache object for storing key-value pairs.") 119 | 120 | ### Contributing 121 | 122 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 123 | 124 | ### Building docs 125 | 126 | _(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_ 127 | 128 | To generate the readme and API documentation with [verb](https://github.com/verbose/verb): 129 | 130 | ```sh 131 | $ npm install -g verb verb-generate-readme && verb 132 | ``` 133 | 134 | ### Running tests 135 | 136 | Install dev dependencies: 137 | 138 | ```sh 139 | $ npm install -d && npm test 140 | ``` 141 | 142 | ### Author 143 | 144 | **Jon Schlinkert** 145 | 146 | * [github/jonschlinkert](https://github.com/jonschlinkert) 147 | * [twitter/jonschlinkert](http://twitter.com/jonschlinkert) 148 | 149 | ### License 150 | 151 | Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert). 152 | Released under the [MIT license](https://github.com/jonschlinkert/fragment-cache/blob/master/LICENSE). 153 | 154 | *** 155 | 156 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.2.0, on October 17, 2016._ -------------------------------------------------------------------------------- /examples.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var FragmentCache = require('./'); 4 | var fragment = new FragmentCache(); 5 | 6 | 7 | fragment.set('foo', 'bar', 'baz'); 8 | console.log(fragment.get('foo')) 9 | console.log(fragment.get('foo', 'bar')) 10 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var gulp = require('gulp'); 4 | var mocha = require('gulp-mocha'); 5 | var istanbul = require('gulp-istanbul'); 6 | var eslint = require('gulp-eslint'); 7 | 8 | var lib = ['index.js', 'lib/**/*.js', 'bin/*.js']; 9 | 10 | gulp.task('coverage', function() { 11 | return gulp.src(lib) 12 | .pipe(istanbul()) 13 | .pipe(istanbul.hookRequire()); 14 | }); 15 | 16 | gulp.task('test', ['coverage'], function() { 17 | return gulp.src('test/*.js') 18 | .pipe(mocha({reporter: 'spec'})) 19 | .pipe(istanbul.writeReports()); 20 | }); 21 | 22 | gulp.task('lint', function() { 23 | return gulp.src(['*.js', 'test/*.js'].concat(lib)) 24 | .pipe(eslint()) 25 | .pipe(eslint.format()); 26 | }); 27 | 28 | gulp.task('default', ['test', 'lint']); 29 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * fragment-cache 3 | * 4 | * Copyright (c) 2016-2017, Jon Schlinkert. 5 | * Released under the MIT License. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | var MapCache = require('map-cache'); 11 | 12 | /** 13 | * Create a new `FragmentCache` with an optional object to use for `caches`. 14 | * 15 | * ```js 16 | * var fragment = new FragmentCache(); 17 | * ``` 18 | * @name FragmentCache 19 | * @param {String} `cacheName` 20 | * @return {Object} Returns the [map-cache][] instance. 21 | * @api public 22 | */ 23 | 24 | function FragmentCache(caches) { 25 | this.caches = caches || {}; 26 | } 27 | 28 | /** 29 | * Prototype 30 | */ 31 | 32 | FragmentCache.prototype = { 33 | 34 | /** 35 | * Get cache `name` from the `fragment.caches` object. Creates a new 36 | * `MapCache` if it doesn't already exist. 37 | * 38 | * ```js 39 | * var cache = fragment.cache('files'); 40 | * console.log(fragment.caches.hasOwnProperty('files')); 41 | * //=> true 42 | * ``` 43 | * @name .cache 44 | * @param {String} `cacheName` 45 | * @return {Object} Returns the [map-cache][] instance. 46 | * @api public 47 | */ 48 | 49 | cache: function(cacheName) { 50 | return this.caches[cacheName] || (this.caches[cacheName] = new MapCache()); 51 | }, 52 | 53 | /** 54 | * Set a value for property `key` on cache `name` 55 | * 56 | * ```js 57 | * fragment.set('files', 'somefile.js', new File({path: 'somefile.js'})); 58 | * ``` 59 | * @name .set 60 | * @param {String} `name` 61 | * @param {String} `key` Property name to set 62 | * @param {any} `val` The value of `key` 63 | * @return {Object} The cache instance for chaining 64 | * @api public 65 | */ 66 | 67 | set: function(cacheName, key, val) { 68 | var cache = this.cache(cacheName); 69 | cache.set(key, val); 70 | return cache; 71 | }, 72 | 73 | /** 74 | * Returns true if a non-undefined value is set for `key` on fragment cache `name`. 75 | * 76 | * ```js 77 | * var cache = fragment.cache('files'); 78 | * cache.set('somefile.js'); 79 | * 80 | * console.log(cache.has('somefile.js')); 81 | * //=> true 82 | * 83 | * console.log(cache.has('some-other-file.js')); 84 | * //=> false 85 | * ``` 86 | * @name .has 87 | * @param {String} `name` Cache name 88 | * @param {String} `key` Optionally specify a property to check for on cache `name` 89 | * @return {Boolean} 90 | * @api public 91 | */ 92 | 93 | has: function(cacheName, key) { 94 | return typeof this.get(cacheName, key) !== 'undefined'; 95 | }, 96 | 97 | /** 98 | * Get `name`, or if specified, the value of `key`. Invokes the [cache]() method, 99 | * so that cache `name` will be created it doesn't already exist. If `key` is not passed, 100 | * the entire cache (`name`) is returned. 101 | * 102 | * ```js 103 | * var Vinyl = require('vinyl'); 104 | * var cache = fragment.cache('files'); 105 | * cache.set('somefile.js', new Vinyl({path: 'somefile.js'})); 106 | * console.log(cache.get('somefile.js')); 107 | * //=> 108 | * ``` 109 | * @name .get 110 | * @param {String} `name` 111 | * @return {Object} Returns cache `name`, or the value of `key` if specified 112 | * @api public 113 | */ 114 | 115 | get: function(name, key) { 116 | var cache = this.cache(name); 117 | if (typeof key === 'string') { 118 | return cache.get(key); 119 | } 120 | return cache; 121 | } 122 | }; 123 | 124 | /** 125 | * Expose `FragmentCache` 126 | */ 127 | 128 | exports = module.exports = FragmentCache; 129 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fragment-cache", 3 | "description": "A cache for managing namespaced sub-caches", 4 | "version": "0.2.1", 5 | "homepage": "https://github.com/jonschlinkert/fragment-cache", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "repository": "jonschlinkert/fragment-cache", 8 | "bugs": { 9 | "url": "https://github.com/jonschlinkert/fragment-cache/issues" 10 | }, 11 | "license": "MIT", 12 | "files": [ 13 | "index.js" 14 | ], 15 | "main": "index.js", 16 | "engines": { 17 | "node": ">=0.10.0" 18 | }, 19 | "scripts": { 20 | "test": "mocha" 21 | }, 22 | "dependencies": { 23 | "map-cache": "^0.2.2" 24 | }, 25 | "devDependencies": { 26 | "gulp": "^3.9.1", 27 | "gulp-eslint": "^3.0.1", 28 | "gulp-format-md": "^0.1.11", 29 | "gulp-istanbul": "^1.1.1", 30 | "gulp-mocha": "^3.0.1", 31 | "mocha": "^3.2.0" 32 | }, 33 | "keywords": [ 34 | "cache", 35 | "fragment" 36 | ], 37 | "verb": { 38 | "plugins": [ 39 | "gulp-format-md" 40 | ], 41 | "reflinks": [ 42 | "map-cache", 43 | "verb" 44 | ], 45 | "related": { 46 | "list": [ 47 | "base", 48 | "map-cache" 49 | ] 50 | }, 51 | "layout": "default", 52 | "toc": false, 53 | "tasks": [ 54 | "readme" 55 | ], 56 | "lint": { 57 | "reflinks": true 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('mocha'); 4 | var assert = require('assert'); 5 | var FragmentCache = require('./'); 6 | var MapCache = require('map-cache'); 7 | 8 | describe('fragment-cache', function() { 9 | it('should export a function', function() { 10 | assert.equal(typeof FragmentCache, 'function'); 11 | }); 12 | 13 | it('should create an instance of FragmentCache', function() { 14 | var fragment = new FragmentCache(); 15 | assert(fragment instanceof FragmentCache); 16 | }); 17 | }); 18 | 19 | describe('methods', function() { 20 | describe('.cache', function() { 21 | it('should create a cache', function() { 22 | var fragment = new FragmentCache(); 23 | fragment.cache('foo'); 24 | assert(fragment.caches.hasOwnProperty('foo')); 25 | }); 26 | 27 | it('should return the cache after creating it', function() { 28 | var fragment = new FragmentCache(); 29 | fragment.cache('foo'); 30 | var cache = fragment.get('foo'); 31 | assert.equal(cache, fragment.caches.foo); 32 | }); 33 | }); 34 | 35 | describe('.get', function() { 36 | it('should get a cache', function() { 37 | var fragment = new FragmentCache(); 38 | fragment.cache('foo'); 39 | var cache = fragment.get('foo'); 40 | assert(cache); 41 | assert.equal(typeof cache, 'object'); 42 | }); 43 | 44 | it('should be an instance of MapCache', function() { 45 | var fragment = new FragmentCache(); 46 | fragment.cache('foo'); 47 | var cache = fragment.get('foo'); 48 | assert(cache); 49 | assert(cache instanceof MapCache); 50 | }); 51 | 52 | it('should get an item from a cache', function() { 53 | var fragment = new FragmentCache(); 54 | var cache = fragment.cache('foo'); 55 | fragment.set('foo', 'a', 'b'); 56 | assert.deepEqual(fragment.get('foo', 'a'), 'b'); 57 | assert.deepEqual(fragment.cache('foo').get('a'), 'b'); 58 | }); 59 | }); 60 | 61 | describe('.set', function() { 62 | it('should set items on the __data__ object of a cache', function() { 63 | var fragment = new FragmentCache(); 64 | var cache = fragment.cache('foo'); 65 | fragment.set('foo', 'a', 'b'); 66 | 67 | assert(cache.__data__.hasOwnProperty('a')); 68 | assert.equal(cache.__data__.a, 'b'); 69 | }); 70 | }); 71 | 72 | describe('.has', function() { 73 | it('should return true when `key` exists on a cache', function() { 74 | var fragment = new FragmentCache(); 75 | var cache = fragment.cache('foo'); 76 | cache.set('a', 'b'); 77 | assert(fragment.has('foo', 'a')); 78 | }); 79 | }); 80 | 81 | describe('.cache.set', function() { 82 | it('should set items on cache.__data__', function() { 83 | var fragment = new FragmentCache(); 84 | var cache = fragment.cache('foo'); 85 | cache.set('a', 'b'); 86 | 87 | assert(cache.__data__.hasOwnProperty('a')); 88 | assert.equal(cache.__data__.a, 'b'); 89 | }); 90 | }); 91 | 92 | describe('.cache.get', function() { 93 | it('should get items from a cache', function() { 94 | var fragment = new FragmentCache(); 95 | var cache = fragment.cache('foo'); 96 | cache.set('a', 'b'); 97 | assert.equal(cache.get('a'), 'b'); 98 | }); 99 | }); 100 | 101 | describe('.cache.has', function() { 102 | it('should return true when an item exists on a cache', function() { 103 | var fragment = new FragmentCache(); 104 | var cache = fragment.cache('foo'); 105 | 106 | cache.set('a', 'b'); 107 | assert(cache.has('a')); 108 | }); 109 | }); 110 | }); 111 | --------------------------------------------------------------------------------