Browse Source

Cache blocks progress

Vova Tkach 5 years ago
parent
commit
abe649dcae
7 changed files with 85 additions and 27 deletions
  1. 9 5
      cblocks/block1.go
  2. 9 5
      cblocks/block2.go
  3. 9 5
      cblocks/block3.go
  4. 9 5
      cblocks/block4.go
  5. 9 5
      cblocks/block5.go
  6. 6 0
      cblocks/cblocks.go
  7. 34 2
      engine/wrapper/wrapper.go

+ 9 - 5
cblocks/block1.go

@@ -4,14 +4,18 @@ import (
 	"html/template"
 )
 
-func (this *CacheBlocks) ResetBlock1(host string) {
-	//
-}
-
 func (this *CacheBlocks) GetBlock1(host, url string) (template.HTML, bool) {
+	if mapCache, ok := this.cacheBlocks[host]; ok {
+		if data, ok := mapCache.CacheBlock1[url]; ok {
+			return data, ok
+		}
+	}
 	return template.HTML(""), false
 }
 
 func (this *CacheBlocks) SetBlock1(host, url string, data template.HTML) {
-	//
+	if _, ok := this.cacheBlocks[host]; !ok {
+		this.cacheBlocks[host] = cache{}
+	}
+	this.cacheBlocks[host].CacheBlock1[url] = data
 }

+ 9 - 5
cblocks/block2.go

@@ -4,14 +4,18 @@ import (
 	"html/template"
 )
 
-func (this *CacheBlocks) ResetBlock2(host string) {
-	//
-}
-
 func (this *CacheBlocks) GetBlock2(host, url string) (template.HTML, bool) {
+	if mapCache, ok := this.cacheBlocks[host]; ok {
+		if data, ok := mapCache.CacheBlock2[url]; ok {
+			return data, ok
+		}
+	}
 	return template.HTML(""), false
 }
 
 func (this *CacheBlocks) SetBlock2(host, url string, data template.HTML) {
-	//
+	if _, ok := this.cacheBlocks[host]; !ok {
+		this.cacheBlocks[host] = cache{}
+	}
+	this.cacheBlocks[host].CacheBlock2[url] = data
 }

+ 9 - 5
cblocks/block3.go

@@ -4,14 +4,18 @@ import (
 	"html/template"
 )
 
-func (this *CacheBlocks) ResetBlock3(host string) {
-	//
-}
-
 func (this *CacheBlocks) GetBlock3(host, url string) (template.HTML, bool) {
+	if mapCache, ok := this.cacheBlocks[host]; ok {
+		if data, ok := mapCache.CacheBlock3[url]; ok {
+			return data, ok
+		}
+	}
 	return template.HTML(""), false
 }
 
 func (this *CacheBlocks) SetBlock3(host, url string, data template.HTML) {
-	//
+	if _, ok := this.cacheBlocks[host]; !ok {
+		this.cacheBlocks[host] = cache{}
+	}
+	this.cacheBlocks[host].CacheBlock3[url] = data
 }

+ 9 - 5
cblocks/block4.go

@@ -4,14 +4,18 @@ import (
 	"html/template"
 )
 
-func (this *CacheBlocks) ResetBlock4(host string) {
-	//
-}
-
 func (this *CacheBlocks) GetBlock4(host, url string) (template.HTML, bool) {
+	if mapCache, ok := this.cacheBlocks[host]; ok {
+		if data, ok := mapCache.CacheBlock4[url]; ok {
+			return data, ok
+		}
+	}
 	return template.HTML(""), false
 }
 
 func (this *CacheBlocks) SetBlock4(host, url string, data template.HTML) {
-	//
+	if _, ok := this.cacheBlocks[host]; !ok {
+		this.cacheBlocks[host] = cache{}
+	}
+	this.cacheBlocks[host].CacheBlock4[url] = data
 }

+ 9 - 5
cblocks/block5.go

@@ -4,14 +4,18 @@ import (
 	"html/template"
 )
 
-func (this *CacheBlocks) ResetBlock5(host string) {
-	//
-}
-
 func (this *CacheBlocks) GetBlock5(host, url string) (template.HTML, bool) {
+	if mapCache, ok := this.cacheBlocks[host]; ok {
+		if data, ok := mapCache.CacheBlock5[url]; ok {
+			return data, ok
+		}
+	}
 	return template.HTML(""), false
 }
 
 func (this *CacheBlocks) SetBlock5(host, url string, data template.HTML) {
-	//
+	if _, ok := this.cacheBlocks[host]; !ok {
+		this.cacheBlocks[host] = cache{}
+	}
+	this.cacheBlocks[host].CacheBlock5[url] = data
 }

+ 6 - 0
cblocks/cblocks.go

@@ -19,3 +19,9 @@ type CacheBlocks struct {
 func New() *CacheBlocks {
 	return &CacheBlocks{}
 }
+
+func (this *CacheBlocks) Reset(host string) {
+	if _, ok := this.cacheBlocks[host]; ok {
+		delete(this.cacheBlocks, host)
+	}
+}

+ 34 - 2
engine/wrapper/wrapper.go

@@ -273,8 +273,8 @@ func (this *Wrapper) ConfigSave() error {
 	return this.Config.configWrite(this.DConfig + string(os.PathSeparator) + "config.json")
 }
 
-func (this *Wrapper) ResetBlock1() {
-	this.c.ResetBlock1(this.Host)
+func (this *Wrapper) ResetBlocks() {
+	this.c.Reset(this.Host)
 }
 
 func (this *Wrapper) GetBlock1() (template.HTML, bool) {
@@ -285,6 +285,38 @@ func (this *Wrapper) SetBlock1(data template.HTML) {
 	this.c.SetBlock1(this.Host, this.R.URL.Path, data)
 }
 
+func (this *Wrapper) GetBlock2() (template.HTML, bool) {
+	return this.c.GetBlock2(this.Host, this.R.URL.Path)
+}
+
+func (this *Wrapper) SetBlock2(data template.HTML) {
+	this.c.SetBlock2(this.Host, this.R.URL.Path, data)
+}
+
+func (this *Wrapper) GetBlock3() (template.HTML, bool) {
+	return this.c.GetBlock3(this.Host, this.R.URL.Path)
+}
+
+func (this *Wrapper) SetBlock3(data template.HTML) {
+	this.c.SetBlock3(this.Host, this.R.URL.Path, data)
+}
+
+func (this *Wrapper) GetBlock4() (template.HTML, bool) {
+	return this.c.GetBlock4(this.Host, this.R.URL.Path)
+}
+
+func (this *Wrapper) SetBlock4(data template.HTML) {
+	this.c.SetBlock4(this.Host, this.R.URL.Path, data)
+}
+
+func (this *Wrapper) GetBlock5() (template.HTML, bool) {
+	return this.c.GetBlock5(this.Host, this.R.URL.Path)
+}
+
+func (this *Wrapper) SetBlock5(data template.HTML) {
+	this.c.SetBlock5(this.Host, this.R.URL.Path, data)
+}
+
 func (this *Wrapper) RemoveProductImageThumbnails(product_id, filename string) error {
 	pattern := this.DHtdocs + string(os.PathSeparator) + strings.Join([]string{"products", "images", product_id, filename}, string(os.PathSeparator))
 	if files, err := filepath.Glob(pattern); err != nil {