Skip to content

Commit 1597eec

Browse files
committed
SEO: Limited sitemap.xml caching to 2 hours
1 parent 3691eaa commit 1597eec

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

src/Libraries/SmartStore.Services/Seo/BaseSitemapGenerator.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Web.Mvc;
55
using System.Xml;
66
using SmartStore.Core;
7+
using SmartStore.Core.Data;
78

89
namespace SmartStore.Services.Seo
910
{
@@ -48,18 +49,21 @@ public string Generate(UrlHelper urlHelper)
4849

4950
public void Generate(UrlHelper urlHelper, Stream stream)
5051
{
51-
_writer = new XmlTextWriter(stream, Encoding.UTF8);
52-
_writer.Formatting = Formatting.Indented;
53-
_writer.WriteStartDocument();
54-
_writer.WriteStartElement("urlset");
55-
_writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
56-
_writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
57-
_writer.WriteAttributeString("xsi:schemaLocation", "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd");
52+
using (var scope = new DbContextScope(autoDetectChanges: false, forceNoTracking: true))
53+
{
54+
_writer = new XmlTextWriter(stream, Encoding.UTF8);
55+
_writer.Formatting = Formatting.Indented;
56+
_writer.WriteStartDocument();
57+
_writer.WriteStartElement("urlset");
58+
_writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
59+
_writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
60+
_writer.WriteAttributeString("xsi:schemaLocation", "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd");
5861

59-
GenerateUrlNodes(urlHelper);
62+
GenerateUrlNodes(urlHelper);
6063

61-
_writer.WriteEndElement();
62-
_writer.Close();
64+
_writer.WriteEndElement();
65+
_writer.Close();
66+
}
6367
}
6468

6569
#endregion

src/Presentation/SmartStore.Web/Controllers/HomeController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public ActionResult SitemapSeo()
207207
var sitemap = _services.Cache.Get(cacheKey, () =>
208208
{
209209
return _sitemapGenerator.Value.Generate(this.Url);
210-
});
210+
}, 120);
211211

212212
return Content(sitemap, "text/xml");
213213
}

0 commit comments

Comments
 (0)