Cache of page/index/index.js and MediaSelector

Enonic version: 7.0.2
OS: Ubuntu 19

Not sure what should the title be but, what is happening is. When I create a content-type with MediaSelector like this one:

<content-type xmlns="urn:enonic:xp:model:1.0">
  <display-name>City</display-name>
  <description>Place where many people live</description>
  <super-type>base:structured</super-type>
  <form>
    <input type="GeoPoint" name="location">
      <label>Location</label>
      <occurrences minimum="1" maximum="1"/>
    </input>
    <input type="Long" name="population">
      <label>Population</label>
      <occurrences minimum="0" maximum="1"/>
      <config>
          <min>1</min>
      </config>
    </input>
    <input name="fil" type="MediaSelector">
      <label>Fil</label>
      <occurrences minimum="0" maximum="1"/>
      <config>
        <allowContentType>media:document</allowContentType>
      </config>
    </input>
  </form>
</content-type>

And then I throw this code right at the start of my page index.js, exports.get:

var content = portal.getContent()

if (content.data.fil) {
    log.info(content.data.fil)
    var url = portal.pageUrl({
        id: content.data.fil,
        type: 'absolute'
    })
    return {
        status: 301,
        headers: {
        Location: url
        }
    }
}

It return me the file selected in the content-type, but after that it doesn’t matter if I remove the file from the content, remove this code from the index.js or remove the input from the content.xml it still return me the file. However if I access this content from another browser it give me the correct page (without the file). So my question is, how do I avoid caching all that?

I think your browser caches 301, since it is a permanent redirect. Try using 302 instead, or set http No cache headers

2 Likes

Oh now I feel silly for posting that. But thanks a lot, that solved it.