cblocks.go 944 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package cblocks
  2. import (
  3. "html/template"
  4. "sync"
  5. )
  6. type cache struct {
  7. CacheBlock1 map[string]template.HTML
  8. CacheBlock2 map[string]template.HTML
  9. CacheBlock3 map[string]template.HTML
  10. CacheBlock4 map[string]template.HTML
  11. CacheBlock5 map[string]template.HTML
  12. }
  13. type CacheBlocks struct {
  14. sync.RWMutex
  15. cacheBlocks map[string]cache
  16. }
  17. func New() *CacheBlocks {
  18. return &CacheBlocks{
  19. cacheBlocks: map[string]cache{},
  20. }
  21. }
  22. func (this *CacheBlocks) prepare(host string) {
  23. if _, ok := this.cacheBlocks[host]; !ok {
  24. this.cacheBlocks[host] = cache{
  25. CacheBlock1: map[string]template.HTML{},
  26. CacheBlock2: map[string]template.HTML{},
  27. CacheBlock3: map[string]template.HTML{},
  28. CacheBlock4: map[string]template.HTML{},
  29. CacheBlock5: map[string]template.HTML{},
  30. }
  31. }
  32. }
  33. func (this *CacheBlocks) Reset(host string) {
  34. this.Lock()
  35. defer this.Unlock()
  36. if _, ok := this.cacheBlocks[host]; ok {
  37. delete(this.cacheBlocks, host)
  38. }
  39. }