VahidN / EFSecondLevelCache.Core

Entity Framework Core Second Level Caching Library
Apache License 2.0
326 stars 51 forks source link

Keys not being generated #22

Closed attiqeurrehman closed 5 years ago

attiqeurrehman commented 5 years ago

Summary of the issue

I am unable to get the correct response from the Redis Cache, it's not creating the collection of keys or creating other keys once it already has the keys for any other get request.

Environment

The in-use version: 1.6.1
Operating system: Windows 10
IDE: VS 2017

Example code/Steps to reproduce:

  1. Add a couple of Employees
  2. Copy & Paste any Id from the Get All request to the Get By Id
  3. See the Redis Cache
  4. Try a couple of other Ids and check the results both on Redis and response you get

Opiniated.zip

Output:

I am not getting the correct response.

VahidN commented 5 years ago

It won't work with ProjectTo of auto-mapper. the Cacheable method needs to evaluate the expression tree to find its dependencies and also its hash and the result of the query (to cache it) and it's not possible with the ProjectTo method.

attiqeurrehman commented 5 years ago

But I have removed it from the get single request handler. I am using ahtomapper after I have the result and it caches first item but not the other items.

-A

On 01-Aug-2018, at 4:53 PM, Vahid Nasiri notifications@github.com wrote:

It won't work with ProjectTo of auto-mapper. the Cacheable method needs to evaluate the expression tree to find dependencies and also its hash and it's not possible with the ProjectTo method.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

attiqeurrehman commented 5 years ago

Following is the code for RestSingleGetHandler

protected override async Task<TSingleGetModel> OnHandleAsync(
            RestSingleGetRequest<TEntity, TSingleGetModel> message,
            CancellationToken cancellationToken)
        {
            var ret = await UnitOfWork.GetRepository<TEntity>()
                .GetAll()
                .Cacheable()
                .FirstOrDefaultAsync(e => e.Id == message.Id, cancellationToken);

            if (ret == null) throw new EntityNotFoundException(typeof(TEntity), message.Id);

            return Mapper.Map<TSingleGetModel>(ret);
        }

It works for the first time and create cache in Redis but for next requests it gives weird results.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related problems.