[SOLVED] ViewHelper Cache


I’ve created my own ViewHelper that returns a random value of an array. Unfortunately the value doesn’t change after several reloads. It only changes after some minutes or when I clear the Flow cache. I’ve already asked Google, but didn’t find anything. Does anyone know how I disable the caching of ViewHelper results?

Kind regards,

Hi Michael,

is this a Flow application or a Neos site?
If the latter, it’s most probably the Content Cache kicking in

Good morning,

it’s a Neos site. So it’s the content cache. But I don’t want to deactivate the whole content caching. Only the result of the view helper. :confused:

Without knowing more about your use case it’s a bit hard to give well-grounded advice but two considerations:

  1. Why not use Fusion to generate the random value
  2. Instead of disabling the content cache, chaning its lifetime to a couple of minutes/hours might be enough in your case. See [SOLVED] Fluid Random Image for an example

Because I have an own node type Jumbotron and there’s an attribute (start) where the user can enter a comma separated list of values (e.g. ‘5,10,17,21,29’). And when You enter the page, randomly a value should be picked from this string. I don’t know how to archive this with Fusion.

Who is the User in this case? An (authenticated?) visitor of your website or the editor using the Neos Backend?

No no, a backend user, sorry :slight_smile:

In this case it could be solved pretty similiar to the linked example:

prototype(Your.Package:NodeType) {
	randomStart = ${Array.first(Array.shuffle(String.split(q(node).property('start'), ',')))}

	@cache {
		# cache for 5 minutes
		maximumLifetime = '300'

And you can access that from the Fluid template via {randomStart}

Thanks, that works fine! :+1:t3: :slight_smile:

1 Like