mirror of
				https://github.com/binwiederhier/ntfy.git
				synced 2025-10-31 13:02:24 +01:00 
			
		
		
		
	Add 'Cache: no' header, closes #41
This commit is contained in:
		
							parent
							
								
									d5be5d3e8c
								
							
						
					
					
						commit
						d6fbccab55
					
				
					 11 changed files with 191 additions and 22 deletions
				
			
		|  | @ -26,7 +26,11 @@ restart**. You can override this behavior using the following config settings: | |||
| 
 | ||||
| * `cache-file`: if set, ntfy will store messages in a SQLite based cache (default is empty, which means in-memory cache). | ||||
|   **This is required if you'd like messages to be retained across restarts**. | ||||
| * `cache-duration`: defines the duration for which messages are stored in the cache (default is `12h`) | ||||
| * `cache-duration`: defines the duration for which messages are stored in the cache (default is `12h`).  | ||||
| 
 | ||||
| You can also entirely disable the cache by setting `cache-duration` to `0`. When the cache is disabled, messages are only | ||||
| passed on to the connected subscribers, but never stored on disk or even kept in memory longer than is needed to forward | ||||
| the message to the subscribers. | ||||
| 
 | ||||
| Subscribers can retrieve cached messaging using the [`poll=1` parameter](subscribe/api.md#polling), as well as the | ||||
| [`since=` parameter](subscribe/api.md#fetching-cached-messages). | ||||
|  | @ -302,7 +306,7 @@ variable before running the `ntfy` command (e.g. `export NTFY_LISTEN_HTTP=:80`). | |||
| | `cert-file` | `NTFY_CERT_FILE` | *filename* | - | HTTPS/TLS certificate file, only used if `listen-https` is set. | | ||||
| | `firebase-key-file` | `NTFY_FIREBASE_KEY_FILE` | *filename* | - | If set, also publish messages to a Firebase Cloud Messaging (FCM) topic for your app. This is optional and only required to save battery when using the Android app. See [Firebase (FCM](#firebase-fcm). | | ||||
| | `cache-file` | `NTFY_CACHE_FILE` | *filename* | - | If set, messages are cached in a local SQLite database instead of only in-memory. This allows for service restarts without losing messages in support of the since= parameter. See [message cache](#message-cache). | | ||||
| | `cache-duration` | `NTFY_CACHE_DURATION` | *duration* | 12h | Duration for which messages will be buffered before they are deleted. This is required to support the `since=...` and `poll=1` parameter. | | ||||
| | `cache-duration` | `NTFY_CACHE_DURATION` | *duration* | 12h | Duration for which messages will be buffered before they are deleted. This is required to support the `since=...` and `poll=1` parameter. Set this to `0` to disable the cache entirely. | | ||||
| | `keepalive-interval` | `NTFY_KEEPALIVE_INTERVAL` | *duration* | 30s | Interval in which keepalive messages are sent to the client. This is to prevent intermediaries closing the connection for inactivity. Note that the Android app has a hardcoded timeout at 77s, so it should be less than that. | | ||||
| | `manager-interval` | `$NTFY_MANAGER_INTERVAL` | *duration* | 1m | Interval in which the manager prunes old messages, deletes topics and prints the stats. | | ||||
| | `global-topic-limit` | `NTFY_GLOBAL_TOPIC_LIMIT` | *number* | 5000 | Rate limiting: Total number of topics before the server rejects new topics. | | ||||
|  |  | |||
|  | @ -49,7 +49,7 @@ If you have the [Android app](subscribe/phone.md) installed on your phone, this | |||
| </figure> | ||||
| 
 | ||||
| There are more features related to publishing messages: You can set a [notification priority](#message-priority),  | ||||
| a [title](#message-title), and [tag messages](#tags-emojis) 🥳 🎉. Here's an example that uses all of them at once: | ||||
| a [title](#message-title), and [tag messages](#tags-emojis) 🥳 🎉. Here's an example that uses some of them at together: | ||||
| 
 | ||||
| === "Command line (curl)" | ||||
|     ``` | ||||
|  | @ -332,3 +332,56 @@ them with a comma, e.g. `tag1,tag2,tag3`. | |||
|   <figcaption>Detail view of notifications with tags</figcaption> | ||||
| </figure> | ||||
| 
 | ||||
| ## Message caching | ||||
| By default, the ntfy server caches messages on disk for 12 hours (see [message caching](config.md#message-cache)), so | ||||
| all messages you publish are stored server-side for a little while. The reason for this is to overcome temporary  | ||||
| client-side network disruptions, but arguably this feature also may raise privacy concerns. | ||||
| 
 | ||||
| To avoid messages being cached server-side entirely, you can set `X-Cache` header (or its alias: `Cache`) to `no`.  | ||||
| This will make sure that your message is not cached on the server, even if server-side caching is enabled. Messages | ||||
| are still delivered to connected subscribers, but [`since=`](subscribe/api.md#fetching-cached-messages) and  | ||||
| [`poll=1`](subscribe/api.md#polling) won't return the message anymore. | ||||
| 
 | ||||
| === "Command line (curl)" | ||||
|     ``` | ||||
|     curl -H "X-Cache: no" -d "This message won't be stored server-side" ntfy.sh/mytopic | ||||
|     curl -H "Cache: no" -d "This message won't be stored server-side" ntfy.sh/mytopic | ||||
|     ``` | ||||
| 
 | ||||
| === "HTTP" | ||||
|     ``` http | ||||
|     POST /mytopic HTTP/1.1 | ||||
|     Host: ntfy.sh | ||||
|     Cache: no | ||||
| 
 | ||||
|     This message won't be stored server-side | ||||
|     ``` | ||||
| 
 | ||||
| === "JavaScript" | ||||
|     ``` javascript | ||||
|     fetch('https://ntfy.sh/mytopic', { | ||||
|         method: 'POST', | ||||
|         body: 'This message won't be stored server-side', | ||||
|         headers: { 'Cache': 'no' } | ||||
|     }) | ||||
|     ``` | ||||
| 
 | ||||
| === "Go" | ||||
|     ``` go | ||||
|     req, _ := http.NewRequest("POST", "https://ntfy.sh/mytopic", strings.NewReader("This message won't be stored server-side")) | ||||
|     req.Header.Set("Cache", "no") | ||||
|     http.DefaultClient.Do(req) | ||||
|     ``` | ||||
| 
 | ||||
| === "PHP" | ||||
|     ``` php-inline | ||||
|     file_get_contents('https://ntfy.sh/mytopic', false, stream_context_create([ | ||||
|         'http' => [ | ||||
|             'method' => 'POST', | ||||
|             'header' => | ||||
|                 "Content-Type: text/plain\r\n" . | ||||
|                 "Cache: no", | ||||
|             'content' => 'This message won't be stored server-side' | ||||
|         ] | ||||
|     ])); | ||||
|     ``` | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Philipp Heckel
						Philipp Heckel