*vital/System/Cache/Memory.txt*	A dictionary instance based cache system

Maintainer: Alisue <lambdalisue@hashnote.net>


==============================================================================
CONTENTS			*Vital.System.Cache.Memory-contents*

Introductions		|Vital.System.Cache.Memory-intro|
Usage			|Vital.System.Cache.Memory-usage|
Functions		|Vital.System.Cache.Memory-functions|
Methods			|Vital.System.Cache.Memory-methods|


==============================================================================
INTRODUCTIONS				*Vital.System.Cache.Memory-intro*

*Vital.System.Cache.Memory* is a dictionary instance based cache system.


==============================================================================
USAGE					*Vital.System.Cache.Memory-usage*

|Vital.System.Cache.Memory| have all required API of unified cache system and
values are stored in a |Dictionary| instance.
In the following example, |Vital.System.Cache.Memory| is used for memorize the
calculated values.
>
	let s:V = vital#{plugin-name}#new()
	let s:C = s:V.import('System.Cache.Memory')

	let s:factorial_cache = s:C.new()

	function! s:factorial(n)
	  if a:n == 0
	    return 1
	  elseif s:factorial_cache.has(a:n)
	    return s:factorial_cache.get(a:n)
	  else
	    let x = s:factorial(a:n - 1) * a:n
	    call s:factorial_cache.set(a:n, x)
	    return x
	  endif
	endfunction

	echo s:factorial(10)
<

==============================================================================
FUNCTIONS				*Vital.System.Cache.Memory-functions*

new([{options}])			*Vital.System.Cache.Memory.new()*

	Create a new instance of System.Cache.Memory.
	No {options} will be used.


==============================================================================
METHODS					*Vital.System.Cache.Memory-methods*

cache_key({obj})	*Vital.System.Cache.Memory-instance.cache_key()*

	See |Vital.System.Cache.Base-instance.cache_key()|

has({name})		*Vital.System.Cache.Memory-instance.has()*

	Return 1 if the cache instance has {name} in its cache dictionary.
	Otherwise 0.

	{name} (required)
	A name of the cache. An actual cache key will be created via
	|Vital.System.Cache.Memory-instance.cache_key()| method thus {name} is
	not required to be |String|.

                        *Vital.System.Cache.Memory-instance.get()*
get({name}[, {default}])

	Return a cached value of {name} in a cache dictionary. It return
	{default} if no value is found.

	{name} (required)
	A name of the cache. An actual cache key will be created via
	|Vital.System.Cache.Memory-instance.cache_key()| method thus {name} is
	not required to be |String|.

	{default} (optional)
	A default value. It will be returned when no value is found in the
	cache dictionary.

set({name}, {value})	*Vital.System.Cache.Memory-instance.set()*

	Save {value} into a cache dictionary as {name}.

	{name} (required)
	A name of the cache. An actual cache key will be created via
	|Vital.System.Cache.Memory-instance.cache_key()| method thus {name} is
	not required to be |String|.

	{value} (required)
	A value of the cache.

keys()			*Vital.System.Cache.Memory-instance.keys()*

	Return a list of cache keys

remove({name})		*Vital.System.Cache.Memory-instance.remove()*

	Remove {name} from a cache dictionary. It does nothing when the
	specified {name} is not found in the cache.

	{name} (required)
	A name of the cache. An actual cache key will be created via
	|Vital.System.Cache.Memory-instance.cache_key()| method thus {name} is
	not required to be |String|.

clear()			*Vital.System.Cache.Memory-instance.clear()*

	Clear a cache dictionary.

on_changed()		*Vital.System.Cache.Memory-instance.on_changed()*

	A user defined hook method. This method is called when the content of
	the cache is changed, namely after the following methods:
	- |Vital.System.Cache.Memory-instance.set()|
	- |Vital.System.Cache.Memory-instance.remove()|
	- |Vital.System.Cache.Memory-instance.clear()|


==============================================================================
vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl
