History

Add in-memory cache to app.Settings to speed up repeated access to settings during arrow key scrolling

Thibaut Courouble committed 9 years ago

Commit 067fa931 parent 188c9d01 file · +16 −7Browse files

Unified · Split

assets/javascripts/app/settings.coffee+16−7
@@ -15,13 +15,21 @@ class app.Settings · 14 unmodified lines
1515
1616 constructor: ->
1717 @store = new CookieStore
18+ @cache = {}
19+
20+ get: (key) ->
21+ return @cache[key] if @cache.hasOwnProperty(key)
22+ @cache[key] = @store.get(key) ? @constructor.defaults[key]
1823
1924 set: (key, value) ->
2025 @store.set(key, value)
26+ delete @cache[key]
2127 return
2228
23− get: (key) ->
24− @store.get(key) ? @constructor.defaults[key]
29+ del: (key) ->
30+ @store.del(key)
31+ delete @cache[key]
32+ return
2533
2634 hasDocs: ->
2735 try !!@store.get(DOCS_KEY)
@@ -30,14 +38,14 @@ class app.Settings · 2 unmodified lines
3038 @store.get(DOCS_KEY)?.split('/') or app.config.default_docs
3139
3240 setDocs: (docs) ->
33− @store.set DOCS_KEY, docs.join('/')
41+ @set DOCS_KEY, docs.join('/')
3442 return
3543
3644 getTips: ->
3745 @store.get(TIPS_KEY)?.split('/') or []
3846
3947 setTips: (tips) ->
40− @store.set TIPS_KEY, tips.join('/')
48+ @set TIPS_KEY, tips.join('/')
4149 return
4250
4351 setLayout: (name, enable) ->
@@ -50,9 +58,9 @@ class app.Settings · 6 unmodified lines
5058 $.arrayDelete(layout, name)
5159
5260 if layout.length > 0
53− @store.set LAYOUT_KEY, layout.join(' ')
61+ @set LAYOUT_KEY, layout.join(' ')
5462 else
55− @store.del LAYOUT_KEY
63+ @del LAYOUT_KEY
5664 return
5765
5866 hasLayout: (name) ->
@@ -60,7 +68,7 @@ class app.Settings · 1 unmodified line
6068 layout.indexOf(name) isnt -1
6169
6270 setSize: (value) ->
63− @store.set SIZE_KEY, value
71+ @set SIZE_KEY, value
6472 return
6573
6674 dump: ->
@@ -68,4 +76,5 @@ class app.Settings · 1 unmodified line
6876
6977 reset: ->
7078 @store.reset()
79+ @cache = {}
7180 return