Пример #1
0
        public void Execute(FileSystemCache cache)
        {
            var path      = cache.GetFilePath(Key);
            var finalPart = path.LastIndexOf('/');

            Directory.CreateDirectory((finalPart == -1)?path:path.Substring(0, finalPart));
            File.WriteAllBytes(path, Data);

            var entry = cache.GetEntry(Key);

            if (entry == null)
            {
                entry           = new FileSystemCacheEntry();
                entry.Key       = Key;
                entry.LastRead  = DateTime.MinValue;
                entry.LastWrite = DateTime.Now;
                entry.Length    = Data.Length;

                cache.AddEntry(entry);
            }
            else
            {
                entry.Length = Data.Length;
            }
        }
Пример #2
0
        internal FileSystemCacheEntry GetEntry(CacheKey key)
        {
            FileSystemCacheEntry entry = null;

            _Index.TryGetValue(key, out entry);
            return(entry);
        }
Пример #3
0
        internal void AddEntry(FileSystemCacheEntry entry)
        {
            var existing = GetEntry(entry.Key);

            if (existing != null)
            {
                _Cache.Remove(existing);
            }

            _Cache.AddLast(entry);
            _Index[entry.Key] = entry;
        }