Ejemplo n.º 1
0
        internal void AddReference(string id, IVowpalWabbitMarshalAction marshalAction)
        {
            List <IncompleteReferenceRequest> requests = null;

            lock (this.lockObject)
            {
                // ignore duplicate keys - still update the sliding timer
                if (this.cache.Contains(id))
                {
                    return;
                }

                this.cache.Add(
                    new CacheItem(id, marshalAction),
                    this.cacheItemPolicyFactory(id));

                requests = (List <IncompleteReferenceRequest>) this.cacheRequests.Get(id);

                if (requests != null)
                {
                    foreach (var req in requests)
                    {
                        req.DontDispose = true;
                    }

                    this.cacheRequests.Remove(id);

                    this.numberOfOpenRequests -= requests.Count;
                }
            }

            // since this can be called from another thread we need to dispatch to the serializer and let it decide
            // when to resolve the marshalling request
            if (requests != null)
            {
                foreach (var req in requests)
                {
                    if (req.Serializer.Resolve(() => req.Marshal(marshalAction)))
                    {
                        this.exampleComplete(req.Serializer);
                    }
                }
            }
        }
        internal void AddReference(string id, IVowpalWabbitMarshalAction marshalAction)
        {
            List<IncompleteReferenceRequest> requests = null;
            lock (this.lockObject)
            {
                // ignore duplicate keys - still update the sliding timer
                if (this.cache.Contains(id))
                    return;

                this.cache.Add(
                    new CacheItem(id, marshalAction),
                    this.cacheItemPolicyFactory(id));

                requests = (List<IncompleteReferenceRequest>)this.cacheRequests.Get(id);

                if (requests != null)
                {
                    foreach (var req in requests)
                        req.DontDispose = true;

                    this.cacheRequests.Remove(id);

                    this.numberOfOpenRequests -= requests.Count;
                }
            }

            // since this can be called from another thread we need to dispatch to the serializer and let it decide
            // when to resolve the marshalling request
            if (requests != null)
            {
                foreach (var req in requests)
                    if (req.Serializer.Resolve(() => req.Marshal(marshalAction)))
                        this.exampleComplete(req.Serializer);
            }
        }