Ejemplo n.º 1
0
            /// <summary>
            /// Commits the insertion into the cache. Once this is called the entry
            /// will be available to clients of the cache.
            /// </summary>
            /// <param name="debugInfo">Debug object for debugging.</param>
            /// <returns>The final resource created.</returns>
            /// <exception cref="IOException">
            /// On errors during the commit.
            /// </exception>
            public IBinaryResource Commit(object debugInfo)
            {
                // The temp resource must be ours!
                FileInfo targetFile = (FileInfo)_parent.GetContentFileFor(_resourceId);

                try
                {
                    FileUtils.Rename(_temporaryFile, targetFile);
                }
                catch (RenameException)
                {
                    CacheErrorCategory category = CacheErrorCategory.WRITE_RENAME_FILE_OTHER;
                    _parent._cacheErrorLogger.LogError(
                        category,
                        typeof(DefaultDiskStorage),
                        "commit");

                    throw;
                }

                if (targetFile.Exists)
                {
                    targetFile.LastWriteTime = _parent._clock.Now;
                }

                return(FileBinaryResource.CreateOrNull(targetFile));
            }
Ejemplo n.º 2
0
        /// <summary>
        /// Remove the resource represented by the entry.
        /// <param name="entry">Entry of the resource to delete.</param>
        /// </summary>
        /// <returns>
        /// Size of deleted file if successfully deleted, -1 otherwise.
        /// </returns>
        public long Remove(IEntry entry)
        {
            // It should be one entry return by us :)
            EntryImpl          entryImpl = (EntryImpl)entry;
            FileBinaryResource resource  = (FileBinaryResource)entryImpl.Resource;

            return(DoRemove(resource.File));
        }
Ejemplo n.º 3
0
 public EntryImpl(string id, FileInfo cachedFile)
 {
     Preconditions.CheckNotNull(cachedFile);
     _id        = Preconditions.CheckNotNull(id);
     _resource  = FileBinaryResource.CreateOrNull(cachedFile);
     _size      = -1;
     _timestamp = default(DateTime);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Get the resource with the specified name.
        /// </summary>
        /// <param name="resourceId">Id of the resource.</param>
        /// <param name="debugInfo">Helper object for debugging.</param>
        /// <returns>
        /// The resource with the specified name. NULL if not found.
        /// </returns>
        /// <exception cref="IOException">
        /// For unexpected behavior.
        /// </exception>
        public IBinaryResource GetResource(string resourceId, object debugInfo)
        {
            FileSystemInfo file = GetContentFileFor(resourceId);

            if (file.Exists)
            {
                file.LastWriteTime = _clock.Now;
                return(FileBinaryResource.CreateOrNull((FileInfo)file));
            }

            return(null);
        }