private int FindObjectPosition(InternalCacheItem[] cache, int itemCount, CacheObjType cacheType, bool findEmpty) {
if (cache==null) {
return -1;
}
//This helps us in the case where we grabbed the cache and then
//somebody added an item, forced a reallocation, and hence made
//itemCount greater than the length of cache.
if (itemCount > cache.Length) {
itemCount = cache.Length;
}
for (int i=0; i<itemCount; i++) {
if (cacheType==cache[i].Key) {
return i;
}
}
if (findEmpty) {
if (itemCount<(cache.Length-1)) {
return itemCount + 1;
}
}
return -1;
}