Browse Source

Cache buster

DarthSim 6 years ago
parent
commit
8030e0aa27
2 changed files with 29 additions and 0 deletions
  1. 13 0
      docs/generating_the_url_advanced.md
  2. 16 0
      processing_options.go

+ 13 - 0
docs/generating_the_url_advanced.md

@@ -198,6 +198,19 @@ Read more about presets in the [Presets](./presets.md) guide.
 
 
 Default: empty
 Default: empty
 
 
+##### Cache buster
+
+```
+cachebuster:%string
+cb:%string
+```
+
+Cache buster doesn't affect image processing but it's changing allows to bypass CDN, proxy server and browser cache. Useful when you have changed some things that are not reflected in the URL like image quality settings, presets or watermark data.
+
+It's highly recommended to prefer `cachebuster` option over URL query string because the option can be properly signed.
+
+Default: empty
+
 ##### Format
 ##### Format
 
 
 ```
 ```

+ 16 - 0
processing_options.go

@@ -118,6 +118,8 @@ type processingOptions struct {
 	Blur       float32
 	Blur       float32
 	Sharpen    float32
 	Sharpen    float32
 
 
+	CacheBuster string
+
 	Watermark watermarkOptions
 	Watermark watermarkOptions
 
 
 	UsedPresets []string
 	UsedPresets []string
@@ -503,6 +505,16 @@ func applyFormatOption(po *processingOptions, args []string) error {
 	return nil
 	return nil
 }
 }
 
 
+func applyCacheBusterOption(po *processingOptions, args []string) error {
+	if len(args) > 1 {
+		return fmt.Errorf("Invalid cache buster arguments: %v", args)
+	}
+
+	po.CacheBuster = args[0]
+
+	return nil
+}
+
 func applyProcessingOption(po *processingOptions, name string, args []string) error {
 func applyProcessingOption(po *processingOptions, name string, args []string) error {
 	switch name {
 	switch name {
 	case "format", "f", "ext":
 	case "format", "f", "ext":
@@ -557,6 +569,10 @@ func applyProcessingOption(po *processingOptions, name string, args []string) er
 		if err := applyPresetOption(po, args); err != nil {
 		if err := applyPresetOption(po, args); err != nil {
 			return err
 			return err
 		}
 		}
+	case "cachebuster", "cb":
+		if err := applyCacheBusterOption(po, args); err != nil {
+			return err
+		}
 	default:
 	default:
 		return fmt.Errorf("Unknown processing option: %s", name)
 		return fmt.Errorf("Unknown processing option: %s", name)
 	}
 	}