Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: eni
- * Date: 17-08-25
- * Time: 11.12.PD
- */
- namespace AppBundle\Service;
- use Doctrine\Common\Cache\Cache;
- use Knp\Bundle\MarkdownBundle\MarkdownParserInterface;
- class MarkdownTransformer
- {
- private $markdownParser;
- private $cache;
- public function __construct(MarkdownParserInterface $markdownParser,Cache $cache)
- {
- $this->markdownParser = $markdownParser;
- $this->cache = $cache;
- }
- public function parse($str)
- {
- $cache = $this->cache;
- $key = md5($str);
- if ($cache->contains($key)) {
- return $cache->fetch($key);
- }
- sleep(1);
- $str = $this->markdownParser
- ->transformMarkdown($str);
- $cache->save($key, $str);
- return $str;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement