2

Hello I am building a system in craft cms using the getharvest api. I have 'translated' the php api to support twig. The problem is the getharvest api is really slow (10+ seconds loading time)

I have solved this problem by using the {% cache %} tag But now my problem is whenever content changes inside the {% cache %} you don't see the updated content but you see the same content as before.

Is there a way I can tell craft to update the cache whenever content changes inside the cache tag?

This is the code I use:

        {% cache globally using key craft.request.getParam('id') %}
            {% set range = craft.harvestapi.setRange %}
            {% set results = craft.harvestapi.getProjectEntries(id, range) %}

            Budget: {{ result.get("data").budget }}<br />
            Uurprijs: {{ result.get("data").get("hourly-rate") }}<br />
            <table>
                <tr>
                    <td><b>Werkzaamheden</b></td>
                    <td><b>Omschrijving</b></td>
                    <td><b>Uren</b></td>
                </tr>
                {% for project in results.get("data") %}
                    {% set taskId = project.get("task-id") %}

                    <tr>
                        <td>{{ craft.harvestapi.getTask(taskId).get("data").get("name") }}</td>
                        <td>{{ project.notes }}</td>
                        <td>{{ project.hours }}</td>
                    </tr>
                {% endfor %}
            </table>
        {% endcache %}

Thanks in advance!

1 Answer 1

1

Because your content is cached it "downloads" your website so it loads quick. This can be fixed by disabling cache to users that are logged in or maybe even certain users. This way you "bypass" the cache so you see the changes as soon as your page is loaded.

unless #

Prevents the {% cache %} tag from activating if a certain condition is met.

{# Don't cache if someone is logged in #}
{% cache unless currentUser %}

You can find the cache options in the docs.

Source: https://craftcms.com/docs/templating/cache

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.