All Bundles

Cache<K:Compare,S>

MRU/LRU object cache

Operations

Code example:

cache := Collection.Cache->New(Cache->Type->LRU, 3)<IntRef, String>;
cache->Insert(415, "San Francisco");
cache->Insert(925, "East Bay");
cache->Insert(650, "Mountain View");

cache->Find(650)->PrintLine();
cache->Find(650)->PrintLine();

cache->Find(415)->PrintLine();

cache->Find(925)->PrintLine();
cache->Find(925)->PrintLine();

cache->Insert(510, "Oakland");
cache->Find(510)->PrintLine();
cache->Find(510)->PrintLine();
cache->Find(510)->PrintLine();

"---"->PrintLine();
values := cache->GetKeys()<IntRef>;
each(value := values) {
   value->PrintLine();
};

New

Default constructor

New(type:Cache->Type, max:Int)
Parameters
NameTypeDescription
typeCache->TypeMRU or LRU cache
maxIntcache max size

Empty

Clears the cache

method : public : Empty() ~ Nil

Find

Searches for a value in cache

method : public : Find(key:K) ~ S
Parameters
NameTypeDescription
keyKsearch key

Return
TypeDescription
Sfound value, Nil if not found

GetKeyValues

Gets a collection of key/value pairs

method : public : GetKeyValues() ~ Vector<Pair<K,S>>
Return
TypeDescription
Vector<Pair<K,S>>vector of key/value pairs

GetKeys

Get a collection of keys

method : public : GetKeys() ~ Vector<K>
Return
TypeDescription
Vector<K>vector of keys

GetValues

Gets a collection of values

method : public : GetValues() ~ Vector<S>
Return
TypeDescription
Vector<S>vector of values

Has

Checks for a value in a cache

method : public : Has(key:K) ~ Bool
Parameters
NameTypeDescription
keyKsearch key

Return
TypeDescription
Booltrue if found, false otherwise

Insert

Inserts a value into the hash

method : public : Insert(key:K, value:S) ~ Bool
Parameters
NameTypeDescription
keyKkey
valueSvalue

IsEmpty

Checks to see if the cache is empty

method : public : IsEmpty() ~ Bool
Return
TypeDescription
Booltrue if empty, false otherwise

Remove

Removes a value from the cache

method : public : Remove(key:K) ~ Bool
Parameters
NameTypeDescription
keyKkey for value to remove

Size

Size of cache

method : public : Size() ~ Int
Return
TypeDescription
Intsize of cache

ToString

Formats the collection into a string. If an element implements the 'Stringify' interface, it's 'ToString()' is called.

method : public : ToString() ~ String
Return
TypeDescription
Stringstring representation