Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShareCacheStruct<T> after RemoveCache,can not load Cache value from db or redis again #19

Open
Jesse1205 opened this issue Jul 15, 2016 · 0 comments

Comments

@Jesse1205
Copy link

Jesse1205 commented Jul 15, 2016

Change the ShareCacheStruct LoadItemFactory function can solve my problem as below

`protected override bool LoadItemFactory(string key, bool isReplace)
{
//string redisKey = CreateRedisKey(key);
//var schema = SchemaTable();
//if (schema != null && schema.AccessLevel == AccessLevel.ReadWrite)
//{
// int periodTime = schema.PeriodTime;
// List dataList;
// if (DataContainer.TryLoadHistory(redisKey, out dataList))
// {
// InitCache(dataList, periodTime);
// return true;
// }
// else
// {
// return false;
// }
//}
string redisKey = CreateRedisKey(key);
TransReceiveParam receiveParam = new TransReceiveParam(redisKey);
receiveParam.Schema = SchemaTable();
int periodTime = receiveParam.Schema.PeriodTime;
int maxCount = receiveParam.Schema.Capacity;

        var provider = Data.DbConnectionProvider.CreateDbProvider(receiveParam.Schema);
        if (receiveParam.Schema.StorageType.HasFlag(StorageType.ReadOnlyDB) ||
            receiveParam.Schema.StorageType.HasFlag(StorageType.ReadWriteDB))
        {
            if (provider == null)
            {
                TraceLog.WriteError("Not found db connection of {0} entity.", receiveParam.Schema.EntityName);
                return false;
            }
            var filter = new DbDataFilter(maxCount);
            if (!string.IsNullOrEmpty(key))
            {
                string[] keyValues = key.Split('-');
                for (int i = 0; i < receiveParam.Schema.Keys.Length; i++)
                {
                    filter.Condition = provider.FormatFilterParam(receiveParam.Schema.Keys[i]);
                    filter.Parameters.Add(receiveParam.Schema.Keys[i], keyValues[i]);
                }
            }
            receiveParam.DbFilter = filter;
        }

        List<T> dataList;
        if (DataContainer.TryReceiveData(receiveParam, out dataList))
        {
            InitCache(dataList, periodTime, isReplace);
            return true;
        }
        else
        {
            return false;
        }
    }`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant