The 'Path' is an expression, composed of forward slashes, asterisks, and other symbols to define what will be affected.
This article explains various operators used in defining rules for path matching and pattern matching. These operators include matching any number of characters, matching recursively, matching characters from a set, matching optional characters, and escaping special characters. The article also provides examples of how these operators can be used to define path rules for Engine "advanced settings" and Cache Purges.
The default path can be considered to be /**/*
, which will affect all images served through the Engine. By comparison, /**/*.jpg
would effect only .jpg files
Any query string parameters on the desired URI may also be specified. If the file name is static, and the query string changes dynamically, make sure to use the patterns described below to target appropriately. For example: `image.jpeg*` will effect all `image.jpeg` variants regardless of any query string.
Operator list
Operator | Description |
* |
Match any number of characters in a single section of the path. e.g. /foo/*.jpg will match /foo/test.jpg but not /foo/bar/test.jpg |
** |
Match any character, any number of times, recursively. e.g. /foo/**.jpg will match both /foo/test.jpg and /foo/bar/test.jpg |
[...] |
Match any character out of a set of characters. e.g./foo/img[0-9][0-9].jpg matches /foo/img01.jpg and /foo/img32.jpg |
? |
Match the proceeding character or range zero or one time. e.g. /foo/imgA?.jpg matches both /foo/img.jpg and /foo/imgA.jpg. e.g. /foo/img[0-9]?.jpg matches both /foo/img.jpg and /foo/img1.jpg |
{a,b,...} |
Match any of the patterns a or b or … e.g. /foo/img.{jpg,png,jpeg} matches /foo/img.jpg, /foo/img.png, and /foo/img.jpeg |
\ |
Escape the special character. e.g. /foo/img.jpg\?thumbnail=true literally matches /foo/img.jpg?thumbnail=true, as opposed to /foo/img.jpgthumbnail=true |
Path Examples
Example | Description |
**/* |
All files in all directories, recursively |
**/*.jpg |
All files in all directories, recursively, ending in .jpg |
/files/* |
All files in the “files” directory |
/files/*.jpg |
All files in the “files” directory ending in .jpg |
/{files,other}/*.jpg |
All files in the “files” or “other” directory ending in .jpg |
|
Files in the “files” directory ending in .jpg where the filename is a single alphanumeric character, case-insensitive
|
Note: When creating a rule for a path that includes a query string, make sure to escape the ?
using the \
operator:/images/image.jpeg\?v=*
The above will match /images/image.jpeg?v=2
.
Examples:
To purge all PNG files under `/images`, non-recursive.
(Files under `/images/today/`, for example, will not be purged.)
/images/*.png
Purge an object with a query string:
Because `?` is an operator in the pattern, the `?` must be escaped using the `\` operator:
/images/image.jpeg\?v=2
The above will match `/images/image.jpeg?v=2`.
To purge everything, recursively:
/**/*
Warning!: Invalidating your entire cache is not advisable. Purging everything all at once will result in performance degradation temporarily as images are being re-cached. To avoid this, only purge subsections at a time.
To purge images from two different locations but with the same name
For the image "12345.jpg", present in two locations, /media/this/path/images/12345.jpg
and /media/that/path/images/12345.jpg
, you could use: /media/**/path/images/12345.jpg
. To purge both files.
To purge images with the same name but different file types
Given two files with the same name, but different formats, such as/media/this/path/images/12345.jpg
and /media/this/path/images/12345.png
, you could use: /media/this/path/images/12345.*
To purge all images sharing a name
To purge all copies of a given image, you could use
use /**/2431122043.png
. To do the same but for any file type, /**/2431122043.*
Comments
0 comments
Please sign in to leave a comment.