1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-05-25 16:23:03 +02:00

Add 'Cache: no' header, closes

This commit is contained in:
Philipp Heckel 2021-12-09 10:23:17 -05:00
parent d5be5d3e8c
commit d6fbccab55
11 changed files with 191 additions and 22 deletions

View file

@ -7,20 +7,35 @@ import (
type memCache struct {
messages map[string][]*message
nop bool
mu sync.Mutex
}
var _ cache = (*memCache)(nil)
// newMemCache creates an in-memory cache
func newMemCache() *memCache {
return &memCache{
messages: make(map[string][]*message),
nop: false,
}
}
// newNopCache creates an in-memory cache that discards all messages;
// it is always empty and can be used if caching is entirely disabled
func newNopCache() *memCache {
return &memCache{
messages: make(map[string][]*message),
nop: true,
}
}
func (s *memCache) AddMessage(m *message) error {
s.mu.Lock()
defer s.mu.Unlock()
if s.nop {
return nil
}
if m.Event != messageEvent {
return errUnexpectedMessageType
}