-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,33 @@ | ||
(function(localStorage) { | ||
(function() { | ||
'use strict'; | ||
|
||
function definition(functionIterate) { | ||
var PREFIX = 'demand', | ||
SUFFIX = 'state', | ||
regexMatchState = new RegExp('^\\[' + PREFIX + '\\]\\[(.+?)\\]\\[' + SUFFIX + '\\]$'), | ||
regexMatchProperties = /^(.+?),(\d+),(\d*),(.+?),(\d+)$/; | ||
|
||
function getState(key) { | ||
var state = localStorage.getItem(key), | ||
matches; | ||
|
||
if(state && (matches = state.match(regexMatchProperties))) { | ||
return Array.prototype.slice.call(matches, 1); | ||
} | ||
} | ||
|
||
function getKey(id) { | ||
return '[' + PREFIX + '][' + id + '][' + SUFFIX + ']'; | ||
} | ||
|
||
functionIterate(localStorage, function(property) { | ||
var match = property.match(regexMatchState), | ||
state; | ||
|
||
if(match) { | ||
state = getState(getKey(match[1])); | ||
|
||
if(!state[4]) { | ||
demand.clear.path(match[1]); | ||
} | ||
} | ||
}); | ||
|
||
function filterStates(property) { | ||
var match = property.match(regexMatchState), | ||
state; | ||
|
||
if(match) { | ||
state = getState(getKey(match[1])); | ||
state[5] = match[1]; | ||
|
||
this.push(state); | ||
} | ||
} | ||
|
||
function definition(functionIterate, cacheStates) { | ||
function compareAccess(a, b) { | ||
if(a[4] < b[4]) { | ||
if(a.accessed < b.accessed) { | ||
return -1; | ||
} | ||
|
||
if(a[4] > b[4]) { | ||
if(a.accessed > b.accessed) { | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
return function cacheDispose(size) { | ||
var states = [], | ||
state; | ||
|
||
functionIterate(localStorage, filterStates, states); | ||
var states = cacheStates(), | ||
item; | ||
|
||
states.sort(compareAccess); | ||
|
||
while(size > 0 && states.length) { | ||
state = states.shift(); | ||
size -= state[1]; | ||
item = states.shift(); | ||
size -= item.size; | ||
|
||
demand.clear.path(state[5]); | ||
demand.cache.clear(item.id); | ||
} | ||
}; | ||
} | ||
|
||
provide([ '/demand/function/iterate' ], definition); | ||
}(localStorage)); | ||
provide([ '/demand/function/iterate', './states' ], definition); | ||
}()); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
(function(localStorage) { | ||
'use strict'; | ||
|
||
function definition(functionIterate) { | ||
var PREFIX = 'demand', | ||
SUFFIX = 'state', | ||
regexMatchState = new RegExp('^\\[' + PREFIX + '\\]\\[(.+?)\\]\\[' + SUFFIX + '\\]$'), | ||
regexMatchProperties = /^(.+?),(\d+),(\d*),(.+?),(\d+)$/; | ||
|
||
function getState(key) { | ||
var state = localStorage.getItem(key), | ||
matches; | ||
|
||
if(state && (matches = state.match(regexMatchProperties))) { | ||
return Array.prototype.slice.call(matches, 1); | ||
} | ||
} | ||
|
||
function getKey(id) { | ||
return '[' + PREFIX + '][' + id + '][' + SUFFIX + ']'; | ||
} | ||
|
||
function filterStates(property) { | ||
var match = property.match(regexMatchState), | ||
state; | ||
|
||
if(match) { | ||
state = getState(getKey(match[1])); | ||
|
||
this.push({ | ||
id: match[1], | ||
version: state[0], | ||
size: parseInt(state[1], 10), | ||
expires: state[2] ? new Date(parseInt(state[2], 10)) : null, | ||
demand: state[3], | ||
accessed: new Date(parseInt(state[4], 10)) | ||
}); | ||
} | ||
} | ||
|
||
return function cacheStats() { | ||
return functionIterate(localStorage, filterStates, []); | ||
}; | ||
} | ||
|
||
provide([ '/demand/function/iterate' ], definition); | ||
}(localStorage)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.