2

I have a need to add an additional line to the cleanupagent section in our web.config in sitecore. I would like to add the following line:

<remove folder="/App_Data/MediaCache" pattern="*.json" maxAge="01.00:00:00" recursive="true">

Here is the config xml.

<sitecore>
  <agent type="Sitecore.Tasks.CleanupAgent">
    <files hint="raw:AddCommand">
      <remove folder="/App_Data/MediaCache" pattern="*.json" maxAge="01.00:00:00" recursive="true" patch:after="files[@hint='raw:AddCommand']"/>
    </files>
  </agent> 
</sitecore>
maz
  • 642
  • 8
  • 14
Chives
  • 75
  • 1
  • 12
  • Possible duplicate of [Sitecore 8:Patching an agent](https://stackoverflow.com/questions/33110980/sitecore-8patching-an-agent) – Jay S Apr 05 '18 at 11:55
  • This post describes how to modify an existing entry. In my case, I need to add an entry before a similar entry. There are posts on how to do this but they are not working for me. Thanks for the assist. – Chives Apr 05 '18 at 15:18
  • No worries, thought it might be the same issue... looks like @jammykam has you covered! – Jay S Apr 06 '18 at 11:50

1 Answers1

2

The problem you are having is that Sitecore is matching to an existing node, the existing folder="/App_Data/MediaCache" element, and replacing that based on it's node matching rules instead of inserting a new one.

In order to prevent it from matching, you need to make your node more unique, the simplest way is to add an additional attribute, e.g. desc="json" (you can also use name or hint attributes instead):

<sitecore>
  <scheduling>
    <agent type="Sitecore.Tasks.CleanupAgent">
      <files>
        <remove folder="/App_Data/MediaCache" pattern="*.json" maxAge="01.00:00:00" recursive="true" desc="json" />
      </files>
    </agent>
  </scheduling>
</sitecore>

The patch should insert a new element in config now instead of replacing.

jammykam
  • 16,940
  • 2
  • 36
  • 71