Twig/Drupal 8 custom cache context not working in node preprocess?
I finally found the solution. My scripts work pretty well, i just forgot one little thing about the cache modules Drupal enable by default in core.

I needed to disable "internal page cache" module and only keep "dynamic page cache" enabled. In fact "internal page cache" works for anonymous users only and caches the whole page in order to get better performance. It is therefore not possible to create dynamic parts and "max-age" or "cache context" doesn't work. So if you disable the module, drupal uses by default "dynamic page cache" and "max-age" or "cache context" will work then.

I hope this helps you.

More infos here :
http://wimleers.com/article/drupal-8-dynamic-page-cache