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
15 15
16 constructor: ->16 constructor: ->
17 @store = new CookieStore17 @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]
18 23
19 set: (key, value) ->24 set: (key, value) ->
20 @store.set(key, value)25 @store.set(key, value)
26 delete @cache[key]
21 return27 return
22 28
23 get: (key) ->29 del: (key) ->
24 @store.get(key) ? @constructor.defaults[key]30 @store.del(key)
31 delete @cache[key]
32 return
25 33
26 hasDocs: ->34 hasDocs: ->
27 try !!@store.get(DOCS_KEY)35 try !!@store.get(DOCS_KEY)
@@ -30,14 +38,14 @@ class app.Settings · 2 unmodified lines
30 @store.get(DOCS_KEY)?.split('/') or app.config.default_docs38 @store.get(DOCS_KEY)?.split('/') or app.config.default_docs
31 39
32 setDocs: (docs) ->40 setDocs: (docs) ->
33 @store.set DOCS_KEY, docs.join('/')41 @set DOCS_KEY, docs.join('/')
34 return42 return
35 43
36 getTips: ->44 getTips: ->
37 @store.get(TIPS_KEY)?.split('/') or []45 @store.get(TIPS_KEY)?.split('/') or []
38 46
39 setTips: (tips) ->47 setTips: (tips) ->
40 @store.set TIPS_KEY, tips.join('/')48 @set TIPS_KEY, tips.join('/')
41 return49 return
42 50
43 setLayout: (name, enable) ->51 setLayout: (name, enable) ->
@@ -50,9 +58,9 @@ class app.Settings · 6 unmodified lines
50 $.arrayDelete(layout, name)58 $.arrayDelete(layout, name)
51 59
52 if layout.length > 060 if layout.length > 0
53 @store.set LAYOUT_KEY, layout.join(' ')61 @set LAYOUT_KEY, layout.join(' ')
54 else62 else
55 @store.del LAYOUT_KEY63 @del LAYOUT_KEY
56 return64 return
57 65
58 hasLayout: (name) ->66 hasLayout: (name) ->
@@ -60,7 +68,7 @@ class app.Settings · 1 unmodified line
60 layout.indexOf(name) isnt -168 layout.indexOf(name) isnt -1
61 69
62 setSize: (value) ->70 setSize: (value) ->
63 @store.set SIZE_KEY, value71 @set SIZE_KEY, value
64 return72 return
65 73
66 dump: ->74 dump: ->
@@ -68,4 +76,5 @@ class app.Settings · 1 unmodified line
68 76
69 reset: ->77 reset: ->
70 @store.reset()78 @store.reset()
79 @cache = {}
71 return80 return