mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-13 01:43:09 -06:00
Update code comments
Signed-off-by: Anant Prakash <anantprakashjsr@gmail.com>
This commit is contained in:
parent
a6e171ddf7
commit
0dbe9e3b27
|
|
@ -19,12 +19,12 @@ import (
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultCleanupPeriod represents time in nanoseconds after which cacheCleanService runs.
|
// DefaultCleanupPeriod represents the default time duration after which cacheCleanService runs.
|
||||||
const DefaultCleanupPeriod time.Duration = 30 * time.Minute
|
const DefaultCleanupPeriod time.Duration = 30 * time.Minute
|
||||||
|
|
||||||
type txnsMap map[string]*util.JSONResponse
|
type txnsMap map[string]*util.JSONResponse
|
||||||
|
|
||||||
// Cache represents a temporary store for entries.
|
// Cache represents a temporary store for response entries.
|
||||||
// Entries are evicted after a certain period, defined by cleanupPeriod.
|
// Entries are evicted after a certain period, defined by cleanupPeriod.
|
||||||
type Cache struct {
|
type Cache struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
|
@ -50,6 +50,7 @@ func New(cleanupPeriodInMins int) *Cache {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FetchTransaction looks up an entry for txnID in Cache.
|
// FetchTransaction looks up an entry for txnID in Cache.
|
||||||
|
// Looks in both the txnMaps.
|
||||||
// Returns (JSON response, true) if txnID is found, else the returned bool is false.
|
// Returns (JSON response, true) if txnID is found, else the returned bool is false.
|
||||||
func (t *Cache) FetchTransaction(txnID string) (*util.JSONResponse, bool) {
|
func (t *Cache) FetchTransaction(txnID string) (*util.JSONResponse, bool) {
|
||||||
t.RLock()
|
t.RLock()
|
||||||
|
|
@ -64,6 +65,7 @@ func (t *Cache) FetchTransaction(txnID string) (*util.JSONResponse, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddTransaction adds an entry for txnID in Cache for later access.
|
// AddTransaction adds an entry for txnID in Cache for later access.
|
||||||
|
// Adds to the front txnMap.
|
||||||
func (t *Cache) AddTransaction(txnID string, res *util.JSONResponse) {
|
func (t *Cache) AddTransaction(txnID string, res *util.JSONResponse) {
|
||||||
t.Lock()
|
t.Lock()
|
||||||
defer t.Unlock()
|
defer t.Unlock()
|
||||||
|
|
@ -73,7 +75,6 @@ func (t *Cache) AddTransaction(txnID string, res *util.JSONResponse) {
|
||||||
|
|
||||||
// cacheCleanService is responsible for cleaning up entries after cleanupPeriod.
|
// cacheCleanService is responsible for cleaning up entries after cleanupPeriod.
|
||||||
// It guarantees that an entry will be present in cache for at least cleanupPeriod & at most 2 * cleanupPeriod.
|
// It guarantees that an entry will be present in cache for at least cleanupPeriod & at most 2 * cleanupPeriod.
|
||||||
// This works by
|
|
||||||
func cacheCleanService(t *Cache) {
|
func cacheCleanService(t *Cache) {
|
||||||
ticker := time.Tick(t.cleanupPeriod)
|
ticker := time.Tick(t.cleanupPeriod)
|
||||||
for range ticker {
|
for range ticker {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue