Skip to content

Commit c9010d2

Browse files
committed
Perf: removed request caching for id resolved entities (EF handles this already per ChangeTracker)
1 parent 36bc1a7 commit c9010d2

26 files changed

Lines changed: 54 additions & 391 deletions

src/Libraries/SmartStore.Services/Blogs/BlogService.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ namespace SmartStore.Services.Blogs
1515
/// </summary>
1616
public partial class BlogService : IBlogService
1717
{
18-
#region Constants
19-
private const string BLOGPOST_BY_ID_KEY = "SmartStore.blogpost.id-{0}";
20-
private const string BLOGPOST_PATTERN_KEY = "SmartStore.blogpost.";
21-
#endregion
2218

2319
#region Fields
2420

@@ -57,8 +53,6 @@ public virtual void DeleteBlogPost(BlogPost blogPost)
5753

5854
_blogPostRepository.Delete(blogPost);
5955

60-
_cacheManager.RemoveByPattern(BLOGPOST_PATTERN_KEY);
61-
6256
//event notification
6357
_eventPublisher.EntityDeleted(blogPost);
6458
}
@@ -73,12 +67,7 @@ public virtual BlogPost GetBlogPostById(int blogPostId)
7367
if (blogPostId == 0)
7468
return null;
7569

76-
string key = string.Format(BLOGPOST_BY_ID_KEY, blogPostId);
77-
return _cacheManager.Get(key, () =>
78-
{
79-
var pv = _blogPostRepository.GetById(blogPostId);
80-
return pv;
81-
});
70+
return _blogPostRepository.GetById(blogPostId);
8271
}
8372

8473
/// <summary>
@@ -208,8 +197,6 @@ public virtual void InsertBlogPost(BlogPost blogPost)
208197

209198
_blogPostRepository.Insert(blogPost);
210199

211-
_cacheManager.RemoveByPattern(BLOGPOST_PATTERN_KEY);
212-
213200
//event notification
214201
_eventPublisher.EntityInserted(blogPost);
215202
}
@@ -225,8 +212,6 @@ public virtual void UpdateBlogPost(BlogPost blogPost)
225212

226213
_blogPostRepository.Update(blogPost);
227214

228-
_cacheManager.RemoveByPattern(BLOGPOST_PATTERN_KEY);
229-
230215
//event notification
231216
_eventPublisher.EntityUpdated(blogPost);
232217
}

src/Libraries/SmartStore.Services/Catalog/CategoryService.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ namespace SmartStore.Services.Catalog
1717
public partial class CategoryService : ICategoryService
1818
{
1919
#region Constants
20-
private const string CATEGORIES_BY_ID_KEY = "SmartStore.category.id-{0}";
2120
private const string CATEGORIES_BY_PARENT_CATEGORY_ID_KEY = "SmartStore.category.byparent-{0}-{1}-{2}-{3}";
2221
private const string PRODUCTCATEGORIES_ALLBYCATEGORYID_KEY = "SmartStore.productcategory.allbycategoryid-{0}-{1}-{2}-{3}-{4}-{5}";
2322
private const string PRODUCTCATEGORIES_ALLBYPRODUCTID_KEY = "SmartStore.productcategory.allbyproductid-{0}-{1}-{2}-{3}";
24-
private const string PRODUCTCATEGORIES_BY_ID_KEY = "SmartStore.productcategory.id-{0}";
2523
private const string CATEGORIES_PATTERN_KEY = "SmartStore.category.";
2624
private const string PRODUCTCATEGORIES_PATTERN_KEY = "SmartStore.productcategory.";
2725

@@ -226,12 +224,7 @@ public virtual Category GetCategoryById(int categoryId)
226224
if (categoryId == 0)
227225
return null;
228226

229-
string key = string.Format(CATEGORIES_BY_ID_KEY, categoryId);
230-
return _cacheManager.Get(key, () =>
231-
{
232-
var category = _categoryRepository.GetById(categoryId);
233-
return category;
234-
});
227+
return _categoryRepository.GetById(categoryId);
235228
}
236229

237230
/// <summary>
@@ -445,11 +438,7 @@ public virtual ProductCategory GetProductCategoryById(int productCategoryId)
445438
if (productCategoryId == 0)
446439
return null;
447440

448-
string key = string.Format(PRODUCTCATEGORIES_BY_ID_KEY, productCategoryId);
449-
return _cacheManager.Get(key, () =>
450-
{
451-
return _productCategoryRepository.GetById(productCategoryId);
452-
});
441+
return _productCategoryRepository.GetById(productCategoryId);
453442
}
454443

455444
/// <summary>

src/Libraries/SmartStore.Services/Catalog/CategoryTemplateService.cs

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ namespace SmartStore.Services.Catalog
1313
/// </summary>
1414
public partial class CategoryTemplateService : ICategoryTemplateService
1515
{
16-
#region Constants
17-
private const string CATEGORYTEMPLATES_BY_ID_KEY = "SmartStore.categorytemplate.id-{0}";
18-
private const string CATEGORYTEMPLATES_ALL_KEY = "SmartStore.categorytemplate.all";
19-
private const string CATEGORYTEMPLATES_PATTERN_KEY = "SmartStore.categorytemplate.";
20-
21-
#endregion
2216

2317
#region Fields
2418

@@ -59,8 +53,6 @@ public virtual void DeleteCategoryTemplate(CategoryTemplate categoryTemplate)
5953

6054
_categoryTemplateRepository.Delete(categoryTemplate);
6155

62-
_cacheManager.RemoveByPattern(CATEGORYTEMPLATES_PATTERN_KEY);
63-
6456
//event notification
6557
_eventPublisher.EntityDeleted(categoryTemplate);
6658
}
@@ -71,16 +63,12 @@ public virtual void DeleteCategoryTemplate(CategoryTemplate categoryTemplate)
7163
/// <returns>Category templates</returns>
7264
public virtual IList<CategoryTemplate> GetAllCategoryTemplates()
7365
{
74-
string key = CATEGORYTEMPLATES_ALL_KEY;
75-
return _cacheManager.Get(key, () =>
76-
{
77-
var query = from pt in _categoryTemplateRepository.Table
78-
orderby pt.DisplayOrder
79-
select pt;
80-
81-
var templates = query.ToList();
82-
return templates;
83-
});
66+
var query = from pt in _categoryTemplateRepository.Table
67+
orderby pt.DisplayOrder
68+
select pt;
69+
70+
var templates = query.ToList();
71+
return templates;
8472
}
8573

8674
/// <summary>
@@ -93,12 +81,7 @@ public virtual CategoryTemplate GetCategoryTemplateById(int categoryTemplateId)
9381
if (categoryTemplateId == 0)
9482
return null;
9583

96-
string key = string.Format(CATEGORYTEMPLATES_BY_ID_KEY, categoryTemplateId);
97-
return _cacheManager.Get(key, () =>
98-
{
99-
var template = _categoryTemplateRepository.GetById(categoryTemplateId);
100-
return template;
101-
});
84+
return _categoryTemplateRepository.GetById(categoryTemplateId);
10285
}
10386

10487
/// <summary>
@@ -112,9 +95,6 @@ public virtual void InsertCategoryTemplate(CategoryTemplate categoryTemplate)
11295

11396
_categoryTemplateRepository.Insert(categoryTemplate);
11497

115-
//cache
116-
_cacheManager.RemoveByPattern(CATEGORYTEMPLATES_PATTERN_KEY);
117-
11898
//event notification
11999
_eventPublisher.EntityInserted(categoryTemplate);
120100
}
@@ -130,9 +110,6 @@ public virtual void UpdateCategoryTemplate(CategoryTemplate categoryTemplate)
130110

131111
_categoryTemplateRepository.Update(categoryTemplate);
132112

133-
//cache
134-
_cacheManager.RemoveByPattern(CATEGORYTEMPLATES_PATTERN_KEY);
135-
136113
//event notification
137114
_eventPublisher.EntityUpdated(categoryTemplate);
138115
}

src/Libraries/SmartStore.Services/Catalog/ManufacturerService.cs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@ namespace SmartStore.Services.Catalog
1616
public partial class ManufacturerService : IManufacturerService
1717
{
1818
#region Constants
19-
private const string MANUFACTURERS_BY_ID_KEY = "SmartStore.manufacturer.id-{0}";
2019
private const string PRODUCTMANUFACTURERS_ALLBYMANUFACTURERID_KEY = "SmartStore.productmanufacturer.allbymanufacturerid-{0}-{1}-{2}-{3}-{4}";
2120
private const string PRODUCTMANUFACTURERS_ALLBYPRODUCTID_KEY = "SmartStore.productmanufacturer.allbyproductid-{0}-{1}-{2}";
22-
private const string PRODUCTMANUFACTURERS_BY_ID_KEY = "SmartStore.productmanufacturer.id-{0}";
23-
private const string MANUFACTURERS_PATTERN_KEY = "SmartStore.manufacturer.";
2421
private const string PRODUCTMANUFACTURERS_PATTERN_KEY = "SmartStore.productmanufacturer.";
2522
#endregion
2623

@@ -161,12 +158,7 @@ public virtual Manufacturer GetManufacturerById(int manufacturerId)
161158
if (manufacturerId == 0)
162159
return null;
163160

164-
string key = string.Format(MANUFACTURERS_BY_ID_KEY, manufacturerId);
165-
return _cacheManager.Get(key, () =>
166-
{
167-
var manufacturer = _manufacturerRepository.GetById(manufacturerId);
168-
return manufacturer;
169-
});
161+
return _manufacturerRepository.GetById(manufacturerId);
170162
}
171163

172164
/// <summary>
@@ -181,7 +173,6 @@ public virtual void InsertManufacturer(Manufacturer manufacturer)
181173
_manufacturerRepository.Insert(manufacturer);
182174

183175
//cache
184-
_cacheManager.RemoveByPattern(MANUFACTURERS_PATTERN_KEY);
185176
_cacheManager.RemoveByPattern(PRODUCTMANUFACTURERS_PATTERN_KEY);
186177

187178
//event notification
@@ -200,7 +191,6 @@ public virtual void UpdateManufacturer(Manufacturer manufacturer)
200191
_manufacturerRepository.Update(manufacturer);
201192

202193
//cache
203-
_cacheManager.RemoveByPattern(MANUFACTURERS_PATTERN_KEY);
204194
_cacheManager.RemoveByPattern(PRODUCTMANUFACTURERS_PATTERN_KEY);
205195

206196
//event notification
@@ -219,7 +209,6 @@ public virtual void DeleteProductManufacturer(ProductManufacturer productManufac
219209
_productManufacturerRepository.Delete(productManufacturer);
220210

221211
//cache
222-
_cacheManager.RemoveByPattern(MANUFACTURERS_PATTERN_KEY);
223212
_cacheManager.RemoveByPattern(PRODUCTMANUFACTURERS_PATTERN_KEY);
224213

225214
//event notification
@@ -355,11 +344,7 @@ public virtual ProductManufacturer GetProductManufacturerById(int productManufac
355344
if (productManufacturerId == 0)
356345
return null;
357346

358-
string key = string.Format(PRODUCTMANUFACTURERS_BY_ID_KEY, productManufacturerId);
359-
return _cacheManager.Get(key, () =>
360-
{
361-
return _productManufacturerRepository.GetById(productManufacturerId);
362-
});
347+
return _productManufacturerRepository.GetById(productManufacturerId);
363348
}
364349

365350
/// <summary>
@@ -374,7 +359,6 @@ public virtual void InsertProductManufacturer(ProductManufacturer productManufac
374359
_productManufacturerRepository.Insert(productManufacturer);
375360

376361
//cache
377-
_cacheManager.RemoveByPattern(MANUFACTURERS_PATTERN_KEY);
378362
_cacheManager.RemoveByPattern(PRODUCTMANUFACTURERS_PATTERN_KEY);
379363

380364
//event notification
@@ -393,7 +377,6 @@ public virtual void UpdateProductManufacturer(ProductManufacturer productManufac
393377
_productManufacturerRepository.Update(productManufacturer);
394378

395379
//cache
396-
_cacheManager.RemoveByPattern(MANUFACTURERS_PATTERN_KEY);
397380
_cacheManager.RemoveByPattern(PRODUCTMANUFACTURERS_PATTERN_KEY);
398381

399382
//event notification

src/Libraries/SmartStore.Services/Catalog/ManufacturerTemplateService.cs

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ namespace SmartStore.Services.Catalog
1313
/// </summary>
1414
public partial class ManufacturerTemplateService : IManufacturerTemplateService
1515
{
16-
#region Constants
17-
private const string MANUFACTURERTEMPLATES_BY_ID_KEY = "SmartStore.manufacturertemplate.id-{0}";
18-
private const string MANUFACTURERTEMPLATES_ALL_KEY = "SmartStore.manufacturertemplate.all";
19-
private const string MANUFACTURERTEMPLATES_PATTERN_KEY = "SmartStore.manufacturertemplate.";
20-
21-
#endregion
2216

2317
#region Fields
2418

@@ -60,8 +54,6 @@ public virtual void DeleteManufacturerTemplate(ManufacturerTemplate manufacturer
6054

6155
_manufacturerTemplateRepository.Delete(manufacturerTemplate);
6256

63-
_cacheManager.RemoveByPattern(MANUFACTURERTEMPLATES_PATTERN_KEY);
64-
6557
//event notification
6658
_eventPublisher.EntityDeleted(manufacturerTemplate);
6759
}
@@ -72,16 +64,12 @@ public virtual void DeleteManufacturerTemplate(ManufacturerTemplate manufacturer
7264
/// <returns>Manufacturer templates</returns>
7365
public virtual IList<ManufacturerTemplate> GetAllManufacturerTemplates()
7466
{
75-
string key = MANUFACTURERTEMPLATES_ALL_KEY;
76-
return _cacheManager.Get(key, () =>
77-
{
78-
var query = from pt in _manufacturerTemplateRepository.Table
79-
orderby pt.DisplayOrder
80-
select pt;
81-
82-
var templates = query.ToList();
83-
return templates;
84-
});
67+
var query = from pt in _manufacturerTemplateRepository.Table
68+
orderby pt.DisplayOrder
69+
select pt;
70+
71+
var templates = query.ToList();
72+
return templates;
8573
}
8674

8775
/// <summary>
@@ -94,12 +82,7 @@ public virtual ManufacturerTemplate GetManufacturerTemplateById(int manufacturer
9482
if (manufacturerTemplateId == 0)
9583
return null;
9684

97-
string key = string.Format(MANUFACTURERTEMPLATES_BY_ID_KEY, manufacturerTemplateId);
98-
return _cacheManager.Get(key, () =>
99-
{
100-
var template = _manufacturerTemplateRepository.GetById(manufacturerTemplateId);
101-
return template;
102-
});
85+
return _manufacturerTemplateRepository.GetById(manufacturerTemplateId);
10386
}
10487

10588
/// <summary>
@@ -113,9 +96,6 @@ public virtual void InsertManufacturerTemplate(ManufacturerTemplate manufacturer
11396

11497
_manufacturerTemplateRepository.Insert(manufacturerTemplate);
11598

116-
//cache
117-
_cacheManager.RemoveByPattern(MANUFACTURERTEMPLATES_PATTERN_KEY);
118-
11999
//event notification
120100
_eventPublisher.EntityInserted(manufacturerTemplate);
121101
}
@@ -131,9 +111,6 @@ public virtual void UpdateManufacturerTemplate(ManufacturerTemplate manufacturer
131111

132112
_manufacturerTemplateRepository.Update(manufacturerTemplate);
133113

134-
//cache
135-
_cacheManager.RemoveByPattern(MANUFACTURERTEMPLATES_PATTERN_KEY);
136-
137114
//event notification
138115
_eventPublisher.EntityUpdated(manufacturerTemplate);
139116
}

src/Libraries/SmartStore.Services/Catalog/ProductAttributeService.cs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ public partial class ProductAttributeService : IProductAttributeService
2121
{
2222
#region Constants
2323
private const string PRODUCTATTRIBUTES_ALL_KEY = "SmartStore.productattribute.all";
24-
private const string PRODUCTATTRIBUTES_BY_ID_KEY = "SmartStore.productattribute.id-{0}";
2524
private const string PRODUCTVARIANTATTRIBUTES_ALL_KEY = "SmartStore.productvariantattribute.all-{0}";
26-
private const string PRODUCTVARIANTATTRIBUTES_BY_ID_KEY = "SmartStore.productvariantattribute.id-{0}";
2725
private const string PRODUCTVARIANTATTRIBUTEVALUES_ALL_KEY = "SmartStore.productvariantattributevalue.all-{0}";
28-
private const string PRODUCTVARIANTATTRIBUTEVALUES_BY_ID_KEY = "SmartStore.productvariantattributevalue.id-{0}";
2926
private const string PRODUCTATTRIBUTES_PATTERN_KEY = "SmartStore.productattribute.";
3027
private const string PRODUCTVARIANTATTRIBUTES_PATTERN_KEY = "SmartStore.productvariantattribute.";
3128
private const string PRODUCTVARIANTATTRIBUTEVALUES_PATTERN_KEY = "SmartStore.productvariantattributevalue.";
@@ -127,12 +124,7 @@ public virtual ProductAttribute GetProductAttributeById(int productAttributeId)
127124
if (productAttributeId == 0)
128125
return null;
129126

130-
string key = string.Format(PRODUCTATTRIBUTES_BY_ID_KEY, productAttributeId);
131-
return _cacheManager.Get(key, () =>
132-
{
133-
var pa = _productAttributeRepository.GetById(productAttributeId);
134-
return pa;
135-
});
127+
return _productAttributeRepository.GetById(productAttributeId);
136128
}
137129

138130
/// <summary>
@@ -226,11 +218,7 @@ public virtual ProductVariantAttribute GetProductVariantAttributeById(int produc
226218
if (productVariantAttributeId == 0)
227219
return null;
228220

229-
string key = string.Format(PRODUCTVARIANTATTRIBUTES_BY_ID_KEY, productVariantAttributeId);
230-
return _cacheManager.Get(key, () =>
231-
{
232-
return _productVariantAttributeRepository.GetById(productVariantAttributeId);
233-
});
221+
return _productVariantAttributeRepository.GetById(productVariantAttributeId);
234222
}
235223

236224
// codehint: sm-add
@@ -345,12 +333,7 @@ public virtual ProductVariantAttributeValue GetProductVariantAttributeValueById(
345333
if (productVariantAttributeValueId == 0)
346334
return null;
347335

348-
string key = string.Format(PRODUCTVARIANTATTRIBUTEVALUES_BY_ID_KEY, productVariantAttributeValueId);
349-
return _cacheManager.Get(key, () =>
350-
{
351-
var pvav = _productVariantAttributeValueRepository.GetById(productVariantAttributeValueId);
352-
return pvav;
353-
});
336+
return _productVariantAttributeValueRepository.GetById(productVariantAttributeValueId);
354337
}
355338

356339
/// <summary>

0 commit comments

Comments
 (0)