mvcct.utils.cache

mvcct.utils.cache is a javascript cache useful to cache responses from the server. Items are inedexed by a string  key. When the the maximum number of entries is reached the oldest entries are deleted.

mvcct.utils.cache(N): it returns a new cache object whose maximum number of entries is N

changeSize(M): it increases the maximum number of items of the cache instance.

add(key, value): it adds a new entry to the cache. key must be a string (if it is a complex object, you may convert it in json)

get(key): it returns the value associated to key, if any, otherwise null.

remove(key): it removes the entry associated to key, if any.

clear(): it removes all entries.

save(key, [session=false], [koMapped=false], [callback=null]): it stores the whole cache content in either local(if session is false) or session storage(if session is true), under the key: key. If koMapped is true, ko.mapping.toJS is applied to the whole set of entries. if a not null callback is provided, each entry x is substituted by callback(x) before storing all entries. The callback is applied to the whole entry that has the format: {  key: ...,   value: ...,  invalid: <true/false> }. The calback is applied beforeko.mapping.fromJS.

load (key, [session=false], [koMapped=false], [callback=null]): loads the whole content of the cache from either local(ifsession is false) or session storage(if session is true), using as the key: key.  If koMapped is true, ko.mapping.fromJS is applied to the whole set of retrieved entries. if a not null callback is provided, each entry x is substituted by callback(x)before inserting all entries in the cache. The callback is applied to the whole entry that has the format: {  key: ...,   value: ...,  invalid: <true/false> }. The calback is applied before ko.mapping.toJS.

Last edited Mar 26, 2013 at 11:07 AM by frankabbruzzese, version 1

Comments

No comments yet.