Ejemplo n.º 1
0
// Parse the bytes into a Liquid template
func Parse(data []byte, config *core.Configuration) (*Template, error) {
	if config == nil {
		config = defaultConfig
	}
	cache := config.GetCache()
	if cache == nil {
		return buildTemplate(data, config)
	}
	hasher := sha1.New()
	hasher.Write(data)
	key := fmt.Sprintf("%x", hasher.Sum(nil))

	template := cache.Get(key)
	if template == nil {
		var err error
		template, err = buildTemplate(data, config)
		if err != nil {
			return nil, err
		}
		cache.Set(key, template)
	}
	return template.(*Template), nil
}