public new bool[] PutMany(
            QueryKey[] keys,
            QueryParameters[] queryParameters,
            ICacheAssembler[][] returnTypes,
            IList[] results,
            ISessionImplementor session)
        {
            if (Log.IsDebugEnabled())
            {
                Log.Debug(
                    "caching query results in region: '{0}'; {1}",
                    RegionName,
                    StringHelper.CollectionToString(keys));
            }

            var cached = new bool[keys.Length];

            var ts = session.Factory.Settings.CacheProvider.NextTimestamp();

            var cachedKeys = new List <object>();

            var cachedResults = new List <object>();

            for (var i = 0; i < keys.Length; i++)
            {
                var result = results[i];
                if (queryParameters[i].NaturalKeyLookup &&
                    result.Count == 0)
                {
                    continue;
                }

                cached[i] = true;
                cachedKeys.Add(keys[i]);

                cachedResults.Add(
                    GetCacheableResult(
                        returnTypes[i],
                        session,
                        result,
                        ts));
            }

            var queryDependencies =
                NCacheProvider.GetQueryDependencyConfigs(_ncacheClient.RegionPrefix);

            _ncacheClient.PutMany(
                cachedKeys.ToArray(),
                cachedResults.ToArray(),
                session,
                queryDependencies);

            return(cached);
        }
        public new async Task <bool> PutAsync(
            QueryKey key,
            QueryParameters queryParameters,
            ICacheAssembler[] returnTypes,
            IList result,
            ISessionImplementor session,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (queryParameters.NaturalKeyLookup &&
                result.Count == 0)
            {
                return(false);
            }

            var ts = session.Factory.Settings.CacheProvider.NextTimestamp();

            if (Log.IsDebugEnabled())
            {
                Log.Debug(
                    "caching query results in region: '{0}'; {1}",
                    RegionName,
                    key);
            }

            var value = await GetCacheableResultAsync(
                returnTypes,
                session,
                result,
                ts,
                cancellationToken)
                        .ConfigureAwait(false);

            var queryDependencies =
                NCacheProvider.GetQueryDependencyConfigs(_ncacheClient.RegionPrefix);

            await _ncacheClient.PutAsync(
                key,
                value,
                session,
                queryDependencies,
                cancellationToken)
            .ConfigureAwait(false);

            return(true);
        }
        public new bool Put(
            QueryKey key,
            QueryParameters queryParameters,
            ICacheAssembler[] returnTypes,
            IList result,
            ISessionImplementor session)
        {
            if (queryParameters.NaturalKeyLookup &&
                result.Count == 0)
            {
                return(false);
            }

            var ts = session.Factory.Settings.CacheProvider.NextTimestamp();

            if (Log.IsDebugEnabled())
            {
                Log.Debug(
                    "caching query results in region: '{0}'; {1}",
                    RegionName,
                    key);
            }

            var queryDependencies =
                NCacheProvider.GetQueryDependencyConfigs(_ncacheClient.RegionPrefix);

            _ncacheClient.Put(
                key,
                GetCacheableResult(
                    returnTypes,
                    session,
                    result,
                    ts),
                session,
                queryDependencies);

            return(true);
        }
Esempio n. 4
0
        private static AggregateCacheDependency GetDependency(
            object key,
            object value,
            string regionPrefix,
            RegionConfig regionConfig,
            string connectionString)
        {
            CacheEntry cachedEntry = null;

            if (value is CachedItem item)
            {
                if (item.Value is CacheEntry entry)
                {
                    cachedEntry = entry;
                }
                else
                {
                    return(null);
                }
            }
            else if (value is CacheLock cacheLock)
            {
                return(null);
            }
            else
            {
                cachedEntry = value as CacheEntry;

                if (cachedEntry == null)
                {
                    return(null);
                }
            }


            var id = (key as CacheKey).Key;


            var entityClassFullName = cachedEntry.Subclass;

            var dependencies = NCacheProvider.GetEntityDependencyConfigs(
                regionPrefix,
                entityClassFullName)
                               .ToArray();

            if (dependencies.Length == 0)
            {
                return(null);
            }

            List <CacheDependency> cacheDependencies =
                new List <CacheDependency>(dependencies.Length);

            for (int i = 0; i < dependencies.Length; i++)
            {
                var cacheDependency =
                    dependencies[i].GetCacheDependency(
                        connectionString,
                        id);

                cacheDependencies.Add(cacheDependency);
            }

            var aggregateDependency = new AggregateCacheDependency();

            aggregateDependency.Add(cacheDependencies.ToArray());

            return(aggregateDependency);
        }