_repository.ToCachedGetById(id);

2 meses atrás
I am beginning my first upgrade, and it's starting way back in the v3's.  I am making progress, but I am running into some things that are over my head.

We've got an extension that was written before my time that uses this call.

_repository.ToCachedGetById(id);

It lives here, which doesn't exist when upgrading to 4x

Nop.Services.Caching.Extensions

Is this enough information to get some advice?
And if so, what would be the equivalent to replace it with?

Any help is very much appreciated.

Have a great day!

2 meses atrás
Now it is GetByIdAsync implemented at the EntityRepository generic class (giving reference from nop v4.6)

 public partial class EntityRepository<TEntity> : IRepository<TEntity> where TEntity : BaseEntity
{
...
public virtual async Task<TEntity> GetByIdAsync(int? id, Func<IStaticCacheManager, CacheKey> getCacheKey = null, bool includeDeleted = true)
{
    if (!id.HasValue || id == 0)
        return null;

    async Task<TEntity> getEntityAsync()
    {
        return await AddDeletedFilter(Table, includeDeleted).FirstOrDefaultAsync(entity => entity.Id == Convert.ToInt32(id));
    }

    if (getCacheKey == null)
        return await getEntityAsync();

    //caching
    var cacheKey = getCacheKey(_staticCacheManager)
        ?? _staticCacheManager.PrepareKeyForDefaultCache(NopEntityCacheDefaults<TEntity>.ByIdCacheKey, id);

    return await _staticCacheManager.GetAsync(cacheKey, getEntityAsync);
}

//Rashed
2 meses atrás
Thank you, thank you!