示例#1
0
        private JsonDocument GetDocumentWithCaching(string key)
        {
            if (key == null)
            {
                return(null);
            }
            JsonDocument doc;

            if (disableCache == false && cache.TryGetValue(key, out doc))
            {
                return(doc);
            }
            doc = actions.Documents.DocumentByKey(key, null);
            EnsureIdInMetadata(doc);
            var nonAuthoritativeInformationBehavior = inFlightTransactionalState.GetNonAuthoritativeInformationBehavior <JsonDocument>(null, key);

            if (nonAuthoritativeInformationBehavior != null)
            {
                doc = nonAuthoritativeInformationBehavior(doc);
            }
            if (disableCache == false)
            {
                cache[key] = doc;
            }
            if (cache.Count > 2048)
            {
                // we are probably doing a stream here, no point in trying to cache things, we might be
                // going through the entire db here!
                disableCache = true;
                cache.Clear();
            }
            return(doc);
        }
示例#2
0
        private JsonDocument GetDocumentWithCaching(string key)
        {
            if (key == null)
            {
                return(null);
            }

            // first we check the dtc state, then the cache and the storage, to avoid race conditions
            var nonAuthoritativeInformationBehavior = inFlightTransactionalState.GetNonAuthoritativeInformationBehavior <JsonDocument>(null, key);

            JsonDocument doc;

            if (disableCache || cache.TryGetValue(key, out doc) == false)
            {
                doc = actions.Documents.DocumentByKey(key);
            }

            if (nonAuthoritativeInformationBehavior != null)
            {
                doc = nonAuthoritativeInformationBehavior(doc);
            }

            JsonDocument.EnsureIdInMetadata(doc);

            if (doc != null && doc.Metadata != null)
            {
                doc.Metadata.EnsureCannotBeChangeAndEnableSnapshotting();
            }

            if (disableCache == false && (doc == null || doc.NonAuthoritativeInformation != true))
            {
                cache[key] = doc;
            }

            if (cache.Count > 2048)
            {
                // we are probably doing a stream here, no point in trying to cache things, we might be
                // going through the entire db here!
                disableCache = true;
                cache.Clear();
            }

            return(doc);
        }