示例#1
0
        /// <summary>
        /// Returns the list of resource references currently registered under the
        /// cache entry.
        /// </summary>
        /// <remarks>
        /// Returns the list of resource references currently registered under the
        /// cache entry. If the list is empty, it returns an empty collection. The
        /// returned collection is unmodifiable and a snapshot of the information at
        /// the time of the query. The state may change after this query returns. The
        /// caller should handle the situation that some or all of these resource
        /// references are no longer relevant.
        /// </remarks>
        /// <returns>
        /// the collection that contains the resource references associated
        /// with the resource; or an empty collection if no resource references
        /// are registered under this resource
        /// </returns>
        public override ICollection <SharedCacheResourceReference> GetResourceReferences(string
                                                                                         key)
        {
            string interned = Intern(key);

            lock (interned)
            {
                SharedCacheResource resource = cachedResources[interned];
                if (resource == null)
                {
                    return(Sharpen.Collections.EmptySet());
                }
                ICollection <SharedCacheResourceReference> refs = new HashSet <SharedCacheResourceReference
                                                                               >(resource.GetResourceReferences());
                return(Sharpen.Collections.UnmodifiableSet(refs));
            }
        }
示例#2
0
        /// <summary>Removes the given resource from the store.</summary>
        /// <remarks>
        /// Removes the given resource from the store. Returns true if the resource is
        /// found and removed or if the resource is not found. Returns false if it was
        /// unable to remove the resource because the resource reference list was not
        /// empty.
        /// </remarks>
        public override bool RemoveResource(string key)
        {
            string interned = Intern(key);

            lock (interned)
            {
                SharedCacheResource resource = cachedResources[interned];
                if (resource == null)
                {
                    return(true);
                }
                if (!resource.GetResourceReferences().IsEmpty())
                {
                    return(false);
                }
                // no users
                Sharpen.Collections.Remove(cachedResources, interned);
                return(true);
            }
        }
示例#3
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();
                    }
                }
            }
        }
示例#4
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);
            }
        }