Ejemplo n.º 1
0
        public void Append(string key, string path, string fileFormat, Type configurationType,
                           CacheItemDirtyChangedHandlerDelegate dirtyChanged = null)
        {
            // build a CacheItem and add to container
            ICacheItem item = null;

            if (fileFormat.EqualsIgnoreCase("xml"))
            {
                item = new XmlFileCacheItem(key, path, configurationType);
            }
            else if (fileFormat.EqualsIgnoreCase("json"))
            {
                item = new JsonFileCacheItem(key, path, configurationType);
            }
            else if (fileFormat.EqualsIgnoreCase("text"))
            {
                item = new TextFileCacheItem(key, path);
            }
            else
            {
                // TODO: throw
            }

            if (dirtyChanged != null)
            {
                item.DirtyChanged += dirtyChanged;
            }

            Container.Add(item);

            // start file monitor
            _FileSystemMonitor.Add(this, path, OnFileChanged, null, null, OnFileRenamed);
        }
Ejemplo n.º 2
0
        public void Remove(string key, CacheItemDirtyChangedHandlerDelegate dirtyChanged = null)
        {
            var item = Container.Get(key) as IFileCacheItem;

            if (item == null)
            {
                // TODO: throw
            }

            if (dirtyChanged != null)
            {
                item.DirtyChanged -= dirtyChanged;
            }

            // stop file monitor
            _FileSystemMonitor.Remove(this, item.Path, OnFileChanged, null, null, OnFileRenamed);

            // remove CacheItem from container
            Container.Remove(key);
        }