Saturday, November 24, 2018

Sitecore Caching


Hi All, In this post we will see about caching mechanism in Sitecore.

Here you go,

  • Sitecore uses various caches to store data, rendered presentation logic and other information in memory in order to improve performance and response time 
  • A cache is a dictionary that keeps track of when each entry is accessed. The data that is stored for each entry depends on the cache.  

Types of cache


                                1. Prefetch cache
                                2. Data cache
                                3. Item cache
                                4. Html or web cache.

Prefetch Cache 


  • There is a prefetch cache for each database.
  • Items are pulled out from database when application starts.
  • Items which should be loaded at startup are specified in App_Config/prefetch folder.
  • Each prefetch entry represents item in a database,this entry includes all field values for all versions including parent-child relationships.
  • Excessive use of prefetch caches can affect the time required for application initialization.

Data Cache 

  • Purpose of this cache is to minimize the amount of requests to the database.
  • There is also data cache for each database.
  • You can specify the data cache in web config

    < setting name = "Caching.DefaultDataCacheSize" value="10MB" />

or you can set as per Database

    < cacheSizes hint = "setting">
        < data > 20MB</data>
        < items > 10MB</items>
        < paths > 500KB</paths>
        < standardValues > 500KB</standardValues>
    </ cacheSizes >

Item Cache 

  •   Like prefetch and data cache,there is an item cache for each database.
  •   This cache has objects of Sitecore.Data.Items.Item

HTML Cache or Web Cache 

  •   Caches the actual HTML generated from renderings and layouts.
  •   You can set HTML Cache per presentation control.
  •   You can set html size and weather it should be enabled for your sites-it all done in the site section of web config

< site name = "website" virtualFolder="/" physicalFolder="/"rootPath="/sitecore/content " startItem="/Home" database="web"domain="extranet" cacheHtml="true" htmlCacheSize="10MB"enablePreview="true" enableWebEdit="true"enableDebugger="true" disableClientData="false" />


    
  Types: 

      1.Vary by Data

  • Sitecore caches the output based on the item accessed.
  • When the same item  is accessed for the second time, the HTML will be loaded from the cache  Typically used for headers and footers. 

  2.Vary by Device 

  • Sitecore caches copies of the output for each Device being used

3.Vary by Param

  • Sitecore caches the output based on rendering parameters passed to the presentation component.

4.Vary by QueryString

  • The VaryByQueryString property controls whether or not output caching varies based on query string parameters passed in the URL.
  • The VaryByParm property causes output caching to vary based on rendering parameter values passed by the developer. The VaryByQueryString property causes output caching to vary based on parameters passed in the URL query string.

5.Vary by User

  • The VaryByUser property controls whether or not output caching varies by the domain and username of the context user. Used with personalization enabled on websites.

6.Vary By Login

  • Controls controls whether or not output caching varies by authenticated user.

To Monitor your caches

              http://< your domain >/Sitecore/admin/cache.aspx 

Flow of Cache in Sitecore


  

Creating the Cache

Creating a cache consists of creating a new instance of Sitecore.Caching.Cache. When the instance is created, the cache is automatically registered within the system. This means that Sitecore recognizes the cache and can control it.
  var mycache = new Sitecore.Caching.Cache("test cache",1024); 

Referencing the Cache

A cache is accessed by name using the Cache Manager.
      var mycache = Sitecore.Caching.CacheManager.FindCacheByName("test cache");

Adding a Value to the Cache
A value is added to the cache using the Add method. 
var mycache =Sitecore.Caching.CacheManager.FindCacheByName("test cache");
mycache.Add("name","value");

Reading a Value from the Cache
A value is read from the cache using the GetValue method.  
var mycache = Sitecore.Caching.CacheManager.FindCacheByName("test cache");
var value =mycache.GetValue("name");

Removing a Value from the Cache
A value is removed from the cache using the Remove method. 
var mycache = Sitecore.Caching.CacheManager.FindCacheByName("test cache");
mycache.Remove("name");

Clearing the Cache
A cache can be cleared using the Clear method. 
var mycache =Sitecore.Caching.CacheManager.FindCacheByName("test cache");
mycache.Clear();


How cache clearing works?
HTML cache
On publishing of any item, HTML cache is cleared.
Item cache
Whenever any item is published, its Item Cache is also updated. If you publish an item which is linked to other items, then these items are cleared as well.

If you publish standard values or a template, it will clear all items based on that template.
Data cache
Data cache is updated incrementally when changes take effect after a publish. It is rebuild incrementally when the items are requested again.
Prefetch cache
Is cleared in the same way as the data cache, but the items specified in the config files are prefetched from the database.


That's all. I Hope now you have a clear view about how caching works in sitecore. Please share this with your friends. Happy Coding :)

Shared and Final Layouts in Sitecore 9


Hi All, In this post we will see about shared and layouts in sitecore.
Let's Move,

In sitecore you can specify presentation details for an item which is shared across different versions of an item or same version/language. 

For each item, you can specify the presentation details for:

The shared layout – stores the presentation details that are shared by all the versions of the item in every language.
The final layout – stores the combination of the presentation details on the selected version of the item and the presentation details of the shared layout. This is the layout that your visitors see on your website.

Shared and final layout has been stored as XML in _Renderings and _Final Renderings field.
_Renderings => Shared
_Final Renderings =>Item version specific.
XML of both files is merged together to create the final presentation.

Add/Edit the layout of an Item:


Step 1:  In the Content Editor or the Experience Editor, navigate to the item or page that you want to edit the layout for.

Step 2:  On the ribbon, on the Presentation tab, in the Layout group, click Details.



Step 3: In the Layout Details dialog box:

      Click the Shared Layout tab to edit the presentation details that apply to all the versions of the item.
     Click the Final Layout tab to edit the presentation details for the current version of the item.




Step 4: Add/Edit the layout,Controls etc.



Step 5: if you want to reset a layout
    On the ribbon, on the Presentation tab, in the Layout group, click Reset.




Please share with your friends. Happy Coding :)

Setting Up Visual Studio For the Project


 Hi all welcome back. in this post we will see about how to setting up visual studio for sitecore solution

Let's Move,


Step 1:  Choosing the right project and location

              Developers use an Asp .net Web Application project using an Visual studio C# in a visual studio to develop Sitecore projects.

Frameworks Supported by the Sitecore
  1.    MVC
  2.    Web Forms


Step 2:  Create a Sample Asp .net Web Application.

    a. Open Visual Studio as an Administrator and click File => New => Project and in the New                           Project dialog, browse to Templates, Visual C#, Web.

      b.  Select ASP.NET Web Application.

      c.  Create a Empty MVC project.







 Step 3:  Delete the Web.Config file of Mvc project and replace with Sitecore Web.Config file.

 Step 4:  Create a folder named as libraries and Copy the below .dll files from your sitecore instance to libraries folder(in Visual Studio) and add these references to your MVC project.

                          Sitecore.Kernel
                         Sitecore.Mvc
                         Sitecore.Analytics

Note: Referencing Sitecore dll’s directly from bin folder is not recommanded.
      
 Step 5:  Replace the Mvc Global.asax file with sitecore Global.asax file.
                  Right click global.asax => View Markup => replace sitecore Global asax

<%@Application Language='C#' Inherits="Sitecore.Web.Application" %>


In the Views/web.config file of your Visual Studio project, add the following Sitecore namespaces to the list of namespaces:
<add namespace="Sitecore.Mvc" />
<add namespace="Sitecore.Mvc.Presentation" />

 Step 6:  Right Click your project and choose Publish and do the below steps

                     Create a new Profile
                     Publish method --File system
                     Target Location -- choose local IIS and give your Sitecore project path.
                    Click Publish




 Step 7:  Right click top of your project and Enable one Web click publish.

 Step 8:  Run your instance and check if it’s works. If you’re facing version issues in System.Web.Mvc related assemblies, please make sure your instance System.Web.Mvc and visual studio System.Web.Mvc ,both have the same version.if not please change to Instance System.Web.Mvc version. 

Sitecore vs Visual studio publishing 



Sitecore
Visual Studio
Action
Move content items from master to web
Move files from the project root folder to website root folder.
Command
Publish
Deploy
Content
Sitecore Items
Code files,Configuration files,dll’s
Tool
Sitecore/Sitecore Rocks
Visual Studio


All now set. Run and work with sitecore. Happy Coding :)

Check the users Logged into the sitecore backend

Hi, Today I'm going to discuss about " how to check the concurrent users logged into the sitecore backend ? ". For this ...