Code Monkey home page Code Monkey logo

dd4t.caching.apachemq's Introduction

AppVeyor

AppVeyor

DD4T.Caching.ApacheMQ

Invalidation of items in the cache when Tridion pages or DCPs are republished or unpublished. Uses the Apache ActiveMQ messaging system.

Release notes for version 2.5

  • Supports Tridion 9 and higher, as well as older versions (6)
  • Upgraded Newtonsoft.Json to 11.0.2

Caching and cache invalidation

DD4T .NET would not work without the help of caching. Any page or component presentation, any link or binary which DD4T retrieves from the Tridion broker, is cached. Normally (if you use the DefaultCacheAgent) all these items are cached in memory by the web application.

If one of these items is changed in the Tridion Content Manager and published, they must be removed from the cache. We call this 'cache invalidation'. The DD4T.Caching.ApacheMQ package allows your DD4T web application to tap in to the messaging system that Tridion itself uses to invalidate the cache of the content service: Apache ActiveMQ.

How to set up cache invalidation with DD4T .NET

To make this work, you need to make changes to the Tridion microservices as well as to your web application. We are assuming that you have set up ActiveMQ already, and your deployer service as well as your content / session service are configured with RemoteSynchronization (see the official documentation).

Configure the microservices

Here is what you need to do to configure your deployer and content (or session) services to use a different CacheConnector:

  1. Download the latest dd4t-cachechannel-xxx.jar from https://github.com/dd4t/dd4t-cachechannel/releases (make sure you get the jar file that works with your version of Tridion)

  2. Copy this jar to the server where your microservices are installed.

  3. Go to the deployer service installation and create a folder 'custom' inside the services folder. You can also give it a different name, or put the jar in one of the existing subfolders of the services folder.

  4. Copy the dd4t-cachechannel-xxx.jar to the newly created folder.

  5. Open cd_storage_conf.xml (in the config folder) in an editor and add the following snippet within the ObjectCache element:

    <RemoteSynchronization FlushCacheDuringDisconnectInterval="20000" Queuesize="5120" ServiceMonitorInterval="10000">
        <Connector Class="org.dd4t.cache.TextJMSCacheChannelConnector" Topic="Tridion">
            <JndiContext>
                <Property Name="java.naming.factory.initial" Value="org.apache.activemq.jndi.ActiveMQInitialContextFactory"/>
                <Property Name="java.naming.provider.url" Value="tcp://127.0.0.1:61616?soTimeout=5000"/>
                <Property Name="topic.Tridion" Value="TridionStaging"/>
                <Property Name="objectMessageSerializationDefered" Value="true"/>
            </JndiContext>
        </Connector>
    </RemoteSynchronization>

You may need to change the following parts of the XML:

  • The value of the property named 'java.naming.provider.url' should point to your Apache ActiveMQ instance
  • The value of the property named 'topic.Tridion' should contain an identifier of your CD environment (e.g. 'staging', 'live', 'dev-staging', etc). The topic is basically the 'feed' that you are subscribing to. The deployer will send messages to this feed, all other clients (content service, your web application) will read from the same feed.
  1. If you are hosting your microservices on a Windows machine, you need to uninstall and re-install the deployer service now. On Linux, just restarting it is enough.

  2. Go onto the content service (it may also be called session service or session-enabled content service), and repeat steps 3 - 6.

Configure your web application

  1. Add a reference to the NuGet package DD4T.Caching.ApacheMQ to your web project.

  2. Look for the following settings in your Web.config (they were added when you added the reference in the previous step):

<add key="DD4T.JMS.Hostname" value="my-tridion-server" />
<add key="DD4T.JMS.Port" value="61616" />
<add key="DD4T.JMS.Topic" value="TridionStaging" />
  1. Make sure the hostname, port and topic are correct. The topic must be the same as the value of 'topic.Tridion' in the configuration of the microservices (see above).

  2. Find the HttpApplication in your project (this is the class that starts the entire web application, normally it is in Global.asax.cs).

  3. Inside the Application_Start method, add the following code:

var dd4tConfiguration = DependencyResolver.Current.GetService<IDD4TConfiguration>();

if (!string.IsNullOrEmpty(dd4tConfiguration.JMSHostname))
{
    var messageProvider = DependencyResolver.Current.GetService<IMessageProvider>() as JMSMessageProvider;
    if (messageProvider != null)
    {
        var cacheAgent = DependencyResolver.Current.GetService<ICacheAgent>();
        if (cacheAgent is DefaultCacheAgent)
        {
            messageProvider.Start();
            ((DefaultCacheAgent)cacheAgent).Subscribe(messageProvider);
        }
    }
}

This starts the message provider (which is responsible for receiving messages from ActiveMQ) and attaches it to the DefaultCacheAgent.

dd4t.caching.apachemq's People

Contributors

quirijnslings avatar ehenderiks avatar

Watchers

James Cloos avatar Albert Romkes avatar  avatar  avatar Rick Pannekoek avatar  avatar  avatar Mihai Cădariu avatar Chris Eccles avatar Rogier Oudshoorn avatar Josh Einhorn avatar  avatar

dd4t.caching.apachemq's Issues

Readme updates

Hi,

Not finding much help online of how to actually use this, any scope for a little more documentation in the readme. I have added the package to my project and added the bits to my web.config. Is there anything to add to my code to actually use these web config entries. I am using the autofac DD4t library to load DD4T

i.e.

builder.UseDD4T();
builder.Build();

would i do something like this ...

 builder.RegisterType<JMSMessageProvider>().As<IMessageProvider>().SingleInstance();
 builder.UseDD4T();

Thanks, Ed

After installation, this module leaves the Web.config in a messy state

The Nuget package contains a Web.config.transform which includes comments to mark the start and the end of the Apache ActiveMQ settings. The starting comment is inserted at the top of the appSettings, the appSettings plus the ending comment at the bottom.
It is better to use a Web.config.install.xdt. This leaves the Web.config in a cleaner state. Also, the comments must be removed.

Key in CacheEvent has changed in post-tridion9 hotfix

After installing an unofficial (and unnumbered) post-tridion9 deployer hotfix, we are seeing that the key of the cache event has changed. It used to be:

1:123:456 (namespace:pubid:itemid)

Now it has become:

1:123:456:PageMeta (namespace:pubid:itemid:class) -- can also be ComponentMeta, BinaryMeta, etc

As a result, invalidation does not take place.
Both styles of keys must be supported.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.