Dispatcher

Dispatcher is Adobe Experience Manager's caching and/or load balancing tool. Dispatcher also helps to protect your AEM server from attack.

The Dispatcher helps realize an environment i.e both fast and dynamic. It works as a part of a static HTML server, with the aim of :

  • Storing as much of the site content as is possible, in the form of static website.
  • Accessing the layout as little as possible. more

Interview Questions

Note: For more on Dispatcher watch this video

Dispatcher is Adobe Experience Manager's caching and/or load balancing tool. Dispatcher also helps to protect your AEM server from attack.

The Dispatcher helps realize an environment i.e both fast and dynamic. It works as a part of a static HTML server, with the aim of :

  • Storing as much of the site content as is possible, in the form of static website.
  • Accessing the layout as little as possible.

For caching, the Dispatcher module uses the Web server's ability to serve static content. The Dispatcher places the cached documents in the document root of the Web server.

The Dispatcher uses the web server's ability to serve static content. The Dispatcher stores cached documents in the web server’s document root. The Dispatcher has two primary methods for updating the cache content when changes are made to the website.

  • Content Updates remove the pages that have changed, as well as files that are directly associated with them.
  • Auto-Invalidation automatically invalidates those parts of the cache that may be out of date after an update. For example, it effectively flags relevant pages as being out of date, without deleting anything.
Example of cache section:

/cache
{
/docroot "/opt/dispatcher/cache"
/statfile "/tmp/dispatcher-website.stat"
/allowAuthorized "0"
/rules
{
# List of files that are cached
}
/invalidate
{
# List of files that are auto-invalidated
}
}

Load Balancing distributes user requests (load) across different clustered CQ instances.The following list describes the advantages for load balancing:

  • Increased processing power: In practice this means that the Dispatcher shares document requests between several instances of AEM. Because each instance has fewer documents to process, you have faster response times. The Dispatcher keeps internal statistics for each document category, so it can estimate the load and distribute the queries efficiently.
  • Increased fail-safe coverage:If the Dispatcher does not receive responses from an instance, it will automatically relay requests to one of the other instance(s). Thus, if an instance becomes unavailable, the only effect is a slowdown of the site, proportionate to the computational power lost.

The /statfile property identifies the file to use as the statfile. Dispatcher uses this file to register the time of the most recent content update. The statfile can be any file on the web server.

The statfile has no content. When content is updated, Dispatcher updates the timestamp. The default statfile is named .stat and is stored in the docroot. Dispatcher blocks access to the statfile. Example:

/cache
{
/docroot "/opt/dispatcher/cache"
/statfile "/tmp/dispatcher-website.stat"
/allowAuthorized "0"
/rules
{
# List of files that are cached
}
/invalidate
{
# List of files that are auto-invalidated
}
}

By default the Dispatcher configuration is stored in the dispatcher.any text file, though you can change the name and location of this file during installation.

The configuration file contains a series of single-valued or multi-valued properties that control the behavior of Dispatcher:

  • Property names are prefixed with a forward slash ("/").
  • Multi-valued properties enclose child items using braces ("{ }").

By default the following requests are not cached by dispatcher

  • Request that do not return http code 200
  • Requests with suffixes
  • Requests with request parameter(i.e ?)
  • Programatically: send http header
    response.setHeader("Dispatcher", "no-cache")

The Dispatcher filter can be used to allow or deny external access to specific areas of AEM. To protect our instance we should configure the Dispatcher to restrict external access as far as possible. First we should deny access to all files and then allow/deny access to specific areas. Example

/filter {
/0001 { /glob "*" /type "deny" }
/0002 { /type "allow" /url "/libs/cq/workflow/content/console*" }
/0003 { /type "deny" /url "/libs/cq/workflow/content/console/archive*" }
}

We can define whether the Dispatcher caches a document by using the Dispatcher configuration file, dispatcher.any. The Dispatcher checks the request against the list of cacheable documents. If the document is not in this list, the Dispatcher requests the document from the AEM instance. The Dispatcher always requests the document directly from the AEM instance in the following cases:

  • If the HTTP method is not GET. Other common methods are POST for form data and HEAD for the HTTP header.
  • If the request URI contains a question mark "?". This usually indicates a dynamic page, such as a search result, which does not need to be cached.
  • The file extension is missing. The web server needs the extension to determine the document type (the MIME-type).
  • The authentication header is set (this can be configured).

The Dispatcher stores cached files on the web server as if they were part of a static website. If a user requests a cached document, the Dispatcher checks whether the document exists in the web server's file system. If so, the Dispatcher returns the documents. If not, the Dispatcher requests the document from the AEM instance.

Yes. For example, if you want to cache only GIF files, specify *.gif in the cache section of the dispatcher.any configuration file.

  • If the document is not subject to auto-invalidation. Dispatcher will consider it as up-to-date.
  • If the document is subject to auto-invalidation. Dispatcher checks whether it is latest version or not. If not Dispatcher will request the current version from AEM.

Yes. In such cases, ensure that both the Dispatchers can access the CQ website directly. A Dispatcher cannot handle requests coming from another Dispatcher.

Yes, if the machine is sufficiently powerful. However, it is recommended that you set up the Dispatcher and the AEM Publish instance on different machines.

For most pages that use sticky connections, you should turn off caching. Otherwise, the same instance of the page is displayed to all users, regardless of the session content.

For some applications, it can be possible to use both sticky connections and caching. For example, if you display a form that writes data to a session, you can use sticky connections and caching in tandem.

Yes we can. But it is very bad idea.

Yes, We can have Dispatcher for AEM author instance.

We can delete files from the CQ cache by using an HTTP request. When the HTTP request is received, Dispatcher deletes the files from the cache. Dispatcher caches the files again only when it receives a client request for the page. Deleting cached files in this manner is appropriate for web sites that are not likely to receive simultaneous requests for the same page.

The HTTP request has the following syntax:

POST /dispatcher/invalidate.cache HTTP/1.1
CQ-Action: Activate
CQ-Handle: path-pattern
Content-Length: 0

Dispatcher deletes the cached files and folders that have names that match the value of the CQ-Handle header. For example, a CQ-Handle of /content/geomtrixx-outdoors/en matches the following items:

  • All files (of any file extension) named en in the geometrixx-outdoors directory
  • Dispatcher only flushes files or directories that match en.* in the geometrixx-outdoors directory. The directory en itself will only be deleted if the "CQ-Action" is "Delete" or "Deactivate".
We have to configure the component(which we don't want to be cached) into Sling Dynamic Include (SDI) configuration.

sling dynamic include


Sling Dynamic Include (SDI) is an OSGi service that is able to automatically replace configured components with the include tags. we can enter list of components (using their resource types) into SDI configuration, choose the include tag type (SSI, ESI or AJAX) and SDI will do the rest. It's totally transparent, we can use it with any components and developers don't have to write any code related to the includes. Every configuration change is seen immediately in the page content. we can enable it only on production machines or on the publish instances, etc. more

We configure caching behavior inside /cache property. Inside /rules property, we can mention the list of cacheable documents.

 /cache
   {
  # Cache configuration
   /rules
   {
     # List of cachable documents
    }
   /invalidate
   {
    # List of auto-invalidated documents
    }
  }

We configure caching behavior inside /cache property. Inside /invalidate property, we can mention the list of documents which are subject to auto-invalidation.

 /cache
   {
  # Cache configuration
   /rules
   {
     # List of cachable documents
    }
   /invalidate
   {
    # List of auto-invalidated documents
    }
  }

The /renders property defines the URL to which Dispatcher sends requests to render a document. The following example /renders section distributes render requests equally among two AEM instances:

 /renders
  {
   /myFirstRenderer
   {
    /hostname "myCompany.com"
     /port "4503"
   }
  /mySecondRenderer
    {
    /hostname "127.0.0.1" #runs on the same computer as Dispatcher
    /port "4503"
    }
   }