Page tree
Skip to end of metadata
Go to start of metadata

Voters are used in Magnolia whenever configuration values are not assigned at startup but instead depend on rules. For example the Cache module has to determine if a requested resource may be cached or not. The rules to determine values should be configurable. The rules are user-defined using voters which evaluate established criteria by determining true or false of each rule. Voters are currently used for:

  • Filter configuration: uses voters to determine whether a filter should be executed or bypassed.
  • Cache configuration: uses voters to determine whether a file should be cached or not.

The basic concept of voters uses Voter classes which calculate an int vote value, where positive (1, 2, 3, ...) results are treated as "yes" or "true" and (0, -1, -2, ...) results are treated as "no" or "false". If you have a set of voters, then the result of a voting is the largest absolute result. If there are two voters with the same absolute result, then the one with the higher positive value will be taken.

Examples:

Vote resultsVoterSet result
-3, 0, 2-3
-3, 0, 33
-3, 0, 44

For most of the "real world" voters only boolean results make sense. These boolean voters return "1" for a "true" and "0" for a "false" result.

Voter examples

VoterParametersBooleanDescription
AuthenticatedVoternoneYesChecks if the current user is authenticated.
ExtensionVoter
  • allow: comma separated lists of allowed extensions.
  • deny: comma separated lists of denied extensions.
Yes
  • Returns false if the extension is not a valid mimetype (as configured in config:/server/MIMEMapping).
  • Returns false if the allow list exists, but the extension is not in the allow list.
  • Returns false if the deny list exists and the extension is in the deny list.
  • Returns true in any other cases.

For further information see the voters package.

 

  • No labels

1 Comment

  1. It might be worth mentioning that by default the Cache will be bypassed for all Requests going to the author Instance (magnoliaAuthor) and those which are made by authenticated users.
    This was a big gotcha for me because i was wondering why the cache didn't work and i had to debug through the filter chain to find this out.

    To get it working, i simply disabled the said Voters under the Config path /modules/cache/config/contentCaching/defaultPageCache/cachePolicy/shouldBypassVoters/deny