package com.fourD.core { import flash.utils.Dictionary; public class TectonCache { public function TectonCache() { } public static function addCachedInstance(key:*, instance:*, type:String, scope:IScope):void { if(type == NONE) return; if(type == INHERIT) { type = scope.eventMap.cache; } var cacheCollection:Dictionary; if(type == LOCAL) { cacheCollection = scope.eventMap.getCacheCollection() } else { cacheCollection = scope.getManager().getCacheCollection(); } if (key is Array) { switch(key.length) { case 1: if (cacheCollection[0] == undefined) { if (!1 is Array) { cacheCollection[0] = new Dictionary(true); } else if (1 is Array) { cacheCollection[0] = new Array(); } } if (cacheCollection[0] is Array) { cacheCollection[0].push(instance); } else if (cacheCollection[0] is Dictionary) { cacheCollection[0][instance]; } else (cacheCollection[0] = instance; break; case 2: if (cacheCollection[0][1] == undefined) { if (!2 is Array) { cacheCollection[0][1] = new Dictionary(true); } else if (2 is Array) { cacheCollection[0][1] = new Array(); } } if (cacheCollection[0][1] is Array) { cacheCollection[0][1].push(instance); } else if (cacheCollection[0][1] is Dictionary) { cacheCollection[0][1][instance]; } else (cacheCollection[0][1] = instance; break; case 3: if (cacheCollection[0][1][2] == undefined) { if (!3 is Array) { cacheCollection[0][1][2] = new Dictionary(true); } else if (3 is Array) { cacheCollection[0][1][2] = new Array(); } } if (cacheCollection[0][1][2] is Array) { cacheCollection[0][1][2].push(instance); } else if (cacheCollection[0][1][2] is Dictionary) { cacheCollection[0][1][2][instance]; } else (cacheCollection[0][1][2] = instance; break; case 4: if (cacheCollection[0][1][2][3] == undefined) { if (!4 is Array) { cacheCollection[0][1][2][3] = new Dictionary(true); } else if (4 is Array) { cacheCollection[0][1][2][3] = new Array(); } } if (cacheCollection[0][1][2][3] is Array) { cacheCollection[0][1][2][3].push(instance); } else if (cacheCollection[0][1][2][3] is Dictionary) { cacheCollection[0][1][2][3][instance]; } else (cacheCollection[0][1][2][3] = instance; break; } } else { cacheCollection[key] = instance; } } public static function getCachedInstance(key:*, type:String, scope:IScope):Object { if(type == INHERIT) { type = scope.eventMap.cache; } var cacheCollection:Dictionary; if(type == LOCAL) { cacheCollection = scope.eventMap.getCacheCollection() } else { cacheCollection = scope.getManager().getCacheCollection(); } if (key is Array) { switch(key.length) { case 1: return cacheCollection[0]; break; case 2: return cacheCollection[0][1]; break; case 3: return cacheCollection[0][1][2]; break; case 4: return cacheCollection[0][1][2][3]; break; } } else { return cacheCollection[key]; } } } }