Exemple #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));
            }
Exemple #2
0
 public EntryImpl(string id, FileInfo cachedFile)
 {
     Preconditions.CheckNotNull(cachedFile);
     _id        = Preconditions.CheckNotNull(id);
     _resource  = FileBinaryResource.CreateOrNull(cachedFile);
     _size      = -1;
     _timestamp = default(DateTime);
 }
Exemple #3
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);
        }