Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

TechMagister/liquid-rust-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

liquid-cache

Cache block for the liquid templating engine ( https://github.com/FerarDuanSednan/liquid-rust )

Still basic, PR are welcome, I'm not anymore improving this.

TODO

  • Improve caching keys ( md5 of the content, etc )
  • Allow a 2nd arg to the filter to set the expiration time

Exemples :

Cache into a folder

let vec = vec![Value::Str("GOOOO".to_string()); 100000];

let text = r#"
{%cache makey %}
  {% for i in vec %}
    My stuff {{ i }}
  {% endfor %}
{% endcache %}
"#;

let mut options : LiquidOptions = Default::default();
options.blocks.insert("cache".to_string(), Box::new(RawCacheBlock::new("./tests/tmp")));

let template = parse(&text, &mut options).unwrap();

let mut data = Context::new();
data.set_val("vec", Value::Array(vec));
data.set_val("makey", Value::Str("cachekeytest".to_string())); // tmp file : ./tests/tmp/cachekeytest

let _ = template.render(&mut data);

Use redis to cache data

// redis
let client = redis::Client::open("redis://127.0.0.1/").unwrap();
let con = Arc::new(Mutex::new(client.get_connection().unwrap()));
// End

let vec = vec![Value::Str("GOOOO".to_string()); 100000];

let text = r#"
{%cache makey %}
  {% for i in vec %}
    My stuff {{ i }}
  {% endfor %}
{% endcache %}
"#;

let mut options : LiquidOptions = Default::default();
options.blocks.insert("cache".to_string(), Box::new(RedisCacheBlock::new(con.clone())));

let template = parse(&text, &mut options).unwrap();

let mut data = Context::new();
data.set_val("vec", Value::Array(vec));
data.set_val("makey", Value::Str("cachekeytest".to_string()));

let _ = template.render(&mut data);

About

Cache block for the liquid templating engine.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages