0

We have two different servers. On one we have CMS and on the other we have frontend. Frontend server is based on Symfony.

We need to built up a caching mechanism/database insertion into the frontend server.

So far I have built up a MySql tables called static_content using doctrine.

enter image description here

And this is the structure inside the Static Content.

enter image description here

This is the current code which I have

    public function parseAction() {
    $staticContent = new StaticContent();
    $staticContent->setData('html');

    $doctrine = $this->getDoctrine()->getManager();
    $doctrine->persist($staticContent);
    $doctrine->flush();

    return new Response($staticContent);
}

public function showExistationalAction($staticContentId) {
    $staticContent = $this->getDoctrine()
        ->getRepository(StaticContent::class)
        ->find($staticContentId);

    if(!$staticContent) {
        throw $this->createNotFoundException(
            'No html has been found'. $staticContentId
        );
    }
    return new Response($staticContent->getData());
}

We are using Symfony 2.8 with MySql 5.7.

So my exact problem is how can I insert the whole web page to Data field in the StaticContent Entity ? Is there a variable which just saves the HTML content in Symfony ? What do I invoke instead of setData('html'); ? Actually I believe that I need guidance.

4
  • And how are you going to invalid the cache of a webpage if the user changes the webpage within the CMS? Commented Feb 2, 2018 at 13:55
  • Hey Thanks Raymond. That's other problem which I am going to solve. One at the time. Commented Feb 2, 2018 at 13:57
  • Why don't you use a cache system like varnish for example ? :) Commented Feb 2, 2018 at 16:48
  • Hey Mcsky, because those are the requirements that I have. Commented Feb 5, 2018 at 7:18

2 Answers 2

1

Try this;

$this->get('doctrine.orm.default_entity_manager')->persist($staticContent);
$this->get('doctrine.orm.default_entity_manager')->flush();
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Mert, for the quick answer. But isn't just this what I am trying ? Could you tell me the difference between this what you have written and $doctrine = $this->getDoctrine()->getManager(); $doctrine->persist($staticContent); $doctrine->flush();
0

You can use the symfony bundle for full page cache. The cache is available for zeroing based on the modification date of the content. https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/cache.html

1 Comment

Hmm, nice solution. But with this I don't insert anything to the database and if I read it correctly I have to put when it expires and I don't want for it ever to expire.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.