public virtual void TestRemoveRef()
        {
            StartEmptyStore();
            string key      = "key1";
            string fileName = "foo.jar";
            string user     = "******";

            // first add the resource
            store.AddResource(key, fileName);
            // add a ref
            ApplicationId id = CreateAppId(1, 1L);
            SharedCacheResourceReference myRef = new SharedCacheResourceReference(id, user);
            string result = store.AddResourceReference(key, myRef);

            NUnit.Framework.Assert.AreEqual(fileName, result);
            ICollection <SharedCacheResourceReference> refs = store.GetResourceReferences(key);

            NUnit.Framework.Assert.AreSame(1, refs.Count);
            NUnit.Framework.Assert.AreEqual(Sharpen.Collections.Singleton(myRef), refs);
            // remove the same ref
            store.RemoveResourceReferences(key, Sharpen.Collections.Singleton(myRef), true);
            ICollection <SharedCacheResourceReference> newRefs = store.GetResourceReferences(key
                                                                                             );

            NUnit.Framework.Assert.IsTrue(newRefs == null || newRefs.IsEmpty());
        }
示例#2
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());
            }
        }
示例#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);
            }
        }
示例#4
0
 public abstract string AddResourceReference(string key, SharedCacheResourceReference
                                             @ref);
示例#5
0
 public abstract bool RemoveResourceReference(string key, SharedCacheResourceReference
                                              @ref, bool updateAccessTime);
 internal virtual bool AddReference(SharedCacheResourceReference @ref)
 {
     return(this.refs.AddItem(@ref));
 }