11using Grand . Business . Core . Interfaces . Customers ;
22using Grand . Data ;
33using Grand . Domain ;
4+ using Grand . Domain . Catalog ;
45using Grand . Domain . Vendors ;
6+ using Grand . Infrastructure . Caching ;
7+ using Grand . Infrastructure . Caching . Constants ;
58using Grand . Infrastructure . Extensions ;
69using MediatR ;
710
@@ -21,10 +24,11 @@ public class VendorService : IVendorService
2124 /// <param name="vendorReviewRepository">Vendor review repository</param>
2225 /// <param name="mediator">Mediator</param>
2326 public VendorService ( IRepository < Vendor > vendorRepository , IRepository < VendorReview > vendorReviewRepository ,
24- IMediator mediator )
27+ ICacheBase cacheBase , IMediator mediator )
2528 {
2629 _vendorRepository = vendorRepository ;
2730 _vendorReviewRepository = vendorReviewRepository ;
31+ _cacheBase = cacheBase ;
2832 _mediator = mediator ;
2933 }
3034
@@ -35,6 +39,7 @@ public VendorService(IRepository<Vendor> vendorRepository, IRepository<VendorRev
3539 private readonly IRepository < Vendor > _vendorRepository ;
3640 private readonly IRepository < VendorReview > _vendorReviewRepository ;
3741 private readonly IMediator _mediator ;
42+ private readonly ICacheBase _cacheBase ;
3843
3944 #endregion
4045
@@ -45,9 +50,10 @@ public VendorService(IRepository<Vendor> vendorRepository, IRepository<VendorRev
4550 /// </summary>
4651 /// <param name="vendorId">Vendor identifier</param>
4752 /// <returns>Vendor</returns>
48- public virtual Task < Vendor > GetVendorById ( string vendorId )
53+ public virtual async Task < Vendor > GetVendorById ( string vendorId )
4954 {
50- return _vendorRepository . GetByIdAsync ( vendorId ) ;
55+ var key = string . Format ( CacheKey . VENDOR_BY_ID_KEY , vendorId ) ;
56+ return await _cacheBase . GetAsync ( key , ( ) => _vendorRepository . GetByIdAsync ( vendorId ) ) ;
5157 }
5258
5359 /// <summary>
@@ -99,6 +105,9 @@ public virtual async Task UpdateVendor(Vendor vendor)
99105
100106 //event notification
101107 await _mediator . EntityUpdated ( vendor ) ;
108+
109+ // clear cache
110+ await _cacheBase . RemoveAsync ( string . Format ( CacheKey . VENDOR_BY_ID_KEY , vendor . Id ) ) ;
102111 }
103112
104113 /// <summary>
@@ -111,6 +120,9 @@ public virtual async Task DeleteVendor(Vendor vendor)
111120
112121 vendor . Deleted = true ;
113122 await UpdateVendor ( vendor ) ;
123+
124+ // clear cache
125+ await _cacheBase . RemoveAsync ( string . Format ( CacheKey . VENDOR_BY_ID_KEY , vendor . Id ) ) ;
114126 }
115127
116128
@@ -250,6 +262,9 @@ public virtual async Task UpdateVendorReviewTotals(Vendor vendor)
250262
251263 //event notification
252264 await _mediator . EntityUpdated ( vendor ) ;
265+
266+ // clear cache
267+ await _cacheBase . RemoveAsync ( string . Format ( CacheKey . VENDOR_BY_ID_KEY , vendor . Id ) ) ;
253268 }
254269
255270 public virtual async Task UpdateVendorReview ( VendorReview vendorReview )
0 commit comments