From 0e093ea0621f03486e273912b2a4bdc1c2b5ace8 Mon Sep 17 00:00:00 2001 From: Derek Guenther Date: Mon, 3 Feb 2014 15:31:19 -0600 Subject: [PATCH] Added a clearCache method to clear the render cache --- docs/api.md | 4 ++++ src/selectize.js | 17 +++++++++++++++++ test/api.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/docs/api.md b/docs/api.md index 2fd42f802..840a59c78 100644 --- a/docs/api.md +++ b/docs/api.md @@ -195,6 +195,10 @@ var selectize = $select[0].selectize; isFull() Returns whether or not the user can select more items. + + clearCache(template) + Clears the render cache. Takes an optional template argument (e.g. "option", "item") to clear only that cache. + ### Related Objects diff --git a/src/selectize.js b/src/selectize.js index 6729778d3..b19909c95 100644 --- a/src/selectize.js +++ b/src/selectize.js @@ -1830,6 +1830,23 @@ $.extend(Selectize.prototype, { } return html; + }, + + /** + * Clears the render cache for a template. If + * no template is given, clears all render + * caches. + * + * @param {string} templateName + */ + clearCache: function(templateName) { + var self = this; + if (typeof templateName === 'undefined') { + self.renderCache = {}; + } else { + delete self.renderCache[templateName]; + } } + }); diff --git a/test/api.js b/test/api.js index 53abb27ba..2c2f10c92 100644 --- a/test/api.js +++ b/test/api.js @@ -567,6 +567,41 @@ }); }); + describe('clearCache()', function() { + var test; + + before(function() { + test = setup_test('