소스 검색

Cache buster

DarthSim 7 년 전
부모
커밋
8030e0aa27
2개의 변경된 파일29개의 추가작업 그리고 0개의 파일을 삭제
  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
 
+##### 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
 
 ```

+ 16 - 0
processing_options.go

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