Class org.as2lib.env.reflect.SimpleCache

org.as2lib.core.BasicClass
   +--org.as2lib.env.reflect.SimpleCache

Implemented Interfaces

Cache

Description

SimpleCache is a simple and performant implementation of the Cache interface.

The caching of classes and packages leads to better performance. You also must cache them because for example the parent of two classes residing in the same package should be the same PackageInfo instance.

This cache is mostly used internally. But you can also use it to add ClassInfo or PackageInfo instances directly so that they do not have to be searched for. This can improve the performance dramatically with classes or packages that are needed quite often.

This implementation sets a variable with name "__as2lib__hashCode" on every cached class and package to offer better performance. Do not delete this property.

Method Index

new SimpleCache()

addClass(), addPackage(), getClass(), getClassByClass(), getClassByInstance(), getPackage(), getRoot(), releaseAll()

Inherited from BasicClass

toString()

Constructor Detail

SimpleCache

public function SimpleCache(root:PackageInfo)

Constructs a new SimpleCache instance.

The root/default package determines where the ClassAlgorithm and PackageAlgorithm classes start their search.

Parameters

rootthe root/default package of the package hierarchy

Method Detail

getClass

public function getClass():ClassInfo

getClassByClass

public function getClassByClass(clazz:Function):ClassInfo

Returns the class info representing the passed-in clazz.

null will be returned if:

  • There is no corresponding ClassInfo instance cached.
  • The passed-in clazz is null or undefined.

Parameters

clazzthe class to return the class info for

Return

the class info representing the passed-in clazz

Specified By

getClassByClass() in org.as2lib.env.reflect.Cache

getClassByInstance

public function getClassByInstance(instance):ClassInfo

Returns the class info representing the class the instance was instantiated of.

null will be returned if:

  • There is no corresponding ClassInfo instance cached.
  • The passed-in instance is null or undefined.

Parameters

instancethe instance to return the appropriate class info for

Return

the class info representing the instance's class

Specified By

getClassByInstance() in org.as2lib.env.reflect.Cache

addClass

public function addClass(info:ClassInfo):ClassInfo

Adds the passed-in classInfo to the list of cached class infos and returns this classInfo.

Parameters

Return

the passed-in and added classInfo

Specified By

addClass() in org.as2lib.env.reflect.Cache

getPackage

public function getPackage(package):PackageInfo

Returns the package info representing the passed-in package.

null will be returned if:

  • There is no corresponding PackageInfo instance cached.
  • The passed-in package is null or undefined.

Parameters

packagethe package to return the appropriate package info for

Return

the pakcage info representing the passed-in package

Specified By

getPackage() in org.as2lib.env.reflect.Cache

addPackage

public function addPackage(info:PackageInfo):PackageInfo

Adds the passed-in packageInfo to this cache and returns this added packageInfo.

Parameters

Return

the passed-in and added packageInfo

Specified By

addPackage() in org.as2lib.env.reflect.Cache

getRoot

public function getRoot(Void):PackageInfo

Returns the root package of the whole package hierarchy.

The root package is also refered to as the default package.

The root/default package determines where the ClassAlgorithm and PackageAlgorithm classes start their search.

Return

the root/default package

Specified By

getRoot() in org.as2lib.env.reflect.Cache

releaseAll

public function releaseAll(Void):Void

Releases all cached class and package infos.

Note that their __as2lib__hashCode variable stays the same.

Specified By

releaseAll() in org.as2lib.env.reflect.Cache