private void SetupRegistry(StorageAddress address) { if (!_intraBlockCache.ContainsKey(address)) { _intraBlockCache[address] = new Stack <int>(); } }
private void SetupCache(StorageAddress address) { if (!_cache.ContainsKey(address)) { _cache[address] = new Stack <int>(); } }
private void PushUpdate(StorageAddress address, byte[] value) { SetupRegistry(address); IncrementPosition(); _intraBlockCache[address].Push(_currentPosition); _changes[_currentPosition] = new Change(ChangeType.Update, address, value); }
private void PushJustCache(StorageAddress address, byte[] value) { SetupCache(address); IncrementPosition(); _cache[address].Push(_currentPosition); _changes[_currentPosition] = new Change(ChangeType.JustCache, address, value); }
private void PushToRegistryOnly(StorageAddress address, byte[] value) { SetupRegistry(address); IncrementPosition(); _intraBlockCache[address].Push(_currentPosition); _originalValues[address] = value; _changes[_currentPosition] = new Change(ChangeType.JustCache, address, value); }
public byte[] GetOriginal(StorageAddress storageAddress) { if (!_originalValues.ContainsKey(storageAddress)) { throw new InvalidOperationException("Get original should only be called after get within the same caching round"); } return(_originalValues[storageAddress]); }
private byte[] LoadFromTree(StorageAddress storageAddress) { StorageTree tree = GetOrCreateStorage(storageAddress.Address); Metrics.StorageTreeReads++; byte[] value = tree.Get(storageAddress.Index); PushToRegistryOnly(storageAddress, value); return(value); }
private byte[] GetThroughCache(StorageAddress storageAddress) { if (_cache.ContainsKey(storageAddress)) { return(_changes[_cache[storageAddress].Peek()].Value); } return(GetAndAddToCache(storageAddress)); }
private byte[] GetAndAddToCache(StorageAddress storageAddress) { //byte[] cached = _storageCache.Get(storageAddress); //if (cached != null) //{ // return cached; //} StorageTree tree = GetOrCreateStorage(storageAddress.Address); Metrics.StorageTreeReads++; byte[] value = tree.Get(storageAddress.Index); PushJustCache(storageAddress, value); //_storageCache.Set(storageAddress, value); return(value); }
// private Dictionary<Address, (int ChangeIndex, StorageTree Storage)> _destructedStorages = new Dictionary<Address, (int, StorageTree)>(); private byte[] GetCurrentValue(StorageAddress storageAddress) { if (_intraBlockCache.ContainsKey(storageAddress)) { int lastChangeIndex = _intraBlockCache[storageAddress].Peek(); // if (_destructedStorages.ContainsKey(storageAddress.Address)) // { // if (lastChangeIndex < _destructedStorages[storageAddress.Address].ChangeIndex) // { // return new byte[] {0}; // } // } return(_changes[lastChangeIndex].Value); } return(LoadFromTree(storageAddress)); }
public void Set(StorageAddress storageAddress, byte[] newValue) { PushUpdate(storageAddress, newValue); }
public byte[] Get(StorageAddress storageAddress) { return(GetCurrentValue(storageAddress)); }
public Change(ChangeType changeType, StorageAddress storageAddress, byte[] value) { StorageAddress = storageAddress; Value = value; ChangeType = changeType; }
public byte[] Get(StorageAddress storageAddress) { return(GetThroughCache(storageAddress)); }