Пример #1
0
        /// <summary>
        /// get data
        /// </summary>
        /// <typeparam name="T">Data type</typeparam>
        /// <param name="command">Cache action command</param>
        /// <returns>Return Data object</returns>
        public async Task <T> GetAsync <T>(GetDataCacheCommand <T> command) where T : BaseEntity <T>, new()
        {
            var query = command.Query;

            if (query != null)
            {
                query.QuerySize = 1;
            }
            var queryResult = dataCachePolicyService.Query <T>(query);

            if (queryResult != null && !queryResult.QueryDatabase)
            {
                return(queryResult.Datas?.FirstOrDefault());
            }
            if (command.GetDatabaseDataProxyAsync != null)
            {
                var data = await command.GetDatabaseDataProxyAsync(query).ConfigureAwait(false);

                dataCachePolicyService.QueryCallback(new QueryDataCallbackContext <T>()
                {
                    Datas = new T[1] {
                        data
                    },
                    Query            = query,
                    PrimaryCacheKeys = queryResult.PrimaryCacheKeys,
                    OtherCacheKeys   = queryResult.OtherCacheKeys
                });
                return(data);
            }
            return(default);
Пример #2
0
 /// <summary>
 /// Get data
 /// </summary>
 /// <typeparam name="T">Data type</typeparam>
 /// <param name="command">Cache action command</param>
 /// <returns>Return data object</returns>
 public T Get <T>(GetDataCacheCommand <T> command) where T : BaseEntity <T>, new()
 {
     return(GetAsync(command).Result);
 }