Example #1
0
        /// <summary>
        /// Adds the provided resource reference to the cache resource under the key,
        /// and updates the access time.
        /// </summary>
        /// <remarks>
        /// Adds the provided resource reference to the cache resource under the key,
        /// and updates the access time. If it returns a non-null value, the caller may
        /// safely assume that the resource will not be removed at least until the app
        /// in this resource reference has terminated.
        /// </remarks>
        /// <returns>the filename of the resource, or null if the resource is not found</returns>
        public override string AddResourceReference(string key, SharedCacheResourceReference
                                                    @ref)
        {
            string interned = Intern(key);

            lock (interned)
            {
                SharedCacheResource resource = cachedResources[interned];
                if (resource == null)
                {
                    // it's not mapped
                    return(null);
                }
                resource.AddReference(@ref);
                resource.UpdateAccessTime();
                return(resource.GetFileName());
            }
        }
Example #2
0
        /// <summary>Removes the provided collection of resource references from the resource.
        ///     </summary>
        /// <remarks>
        /// Removes the provided collection of resource references from the resource.
        /// If the resource does not exist, nothing will be done.
        /// </remarks>
        public override void RemoveResourceReferences(string key, ICollection <SharedCacheResourceReference
                                                                               > refs, bool updateAccessTime)
        {
            string interned = Intern(key);

            lock (interned)
            {
                SharedCacheResource resource = cachedResources[interned];
                if (resource != null)
                {
                    ICollection <SharedCacheResourceReference> resourceRefs = resource.GetResourceReferences
                                                                                  ();
                    resourceRefs.RemoveAll(refs);
                    if (updateAccessTime)
                    {
                        resource.UpdateAccessTime();
                    }
                }
            }
        }
Example #3
0
        /// <summary>Removes the provided resource reference from the resource.</summary>
        /// <remarks>
        /// Removes the provided resource reference from the resource. If the resource
        /// does not exist, nothing will be done.
        /// </remarks>
        public override bool RemoveResourceReference(string key, SharedCacheResourceReference
                                                     @ref, bool updateAccessTime)
        {
            string interned = Intern(key);

            lock (interned)
            {
                bool removed = false;
                SharedCacheResource resource = cachedResources[interned];
                if (resource != null)
                {
                    ICollection <SharedCacheResourceReference> resourceRefs = resource.GetResourceReferences
                                                                                  ();
                    removed = resourceRefs.Remove(@ref);
                    if (updateAccessTime)
                    {
                        resource.UpdateAccessTime();
                    }
                }
                return(removed);
            }
        }