using System;
using System.Threading.Tasks;
using System.Transactions;
using Abp.Domain.Entities.Caching;
using Abp.Domain.Repositories;
using Abp.Domain.Uow;
using Abp.Runtime.Caching;

namespace YGNT.File.Core.Cache
{

    public class FileCache : EntityCache<File, FileCacheItem, Guid>, IFileCache
    {
        public FileCache(ICacheManager cacheManager, IRepository<File, Guid> repository, string cacheName = null) : base(cacheManager, repository, cacheName)
        {
        }

        [UnitOfWork(TransactionScopeOption.Suppress, false)]
        protected override async Task<File> GetEntityFromDataSourceAsync(Guid id)
        {
            var entity = await Repository.FirstOrDefaultAsync(id);
            return entity;
        } 

        [UnitOfWork(TransactionScopeOption.Suppress, false)]
        protected override File GetEntityFromDataSource(Guid id)
        {
            var entity = Repository.FirstOrDefault(id);
            return entity;
        }
    }
}