<p>If I understand you correctly, you’d basically need it to store separate caches depending on the limit.</p>

<p>The way to do that would be to set a custom key on the <code>{% cache %}</code> tag with the <a href="http://buildwithcraft.com/docs/templating/cache#using-key" rel="nofollow"><code>using key</code></a> param:</p>

<pre><code>{% if postCount is not defined or not postCount %}
    {% set postCount = 12 %}
{% endif %}

{% cache using key "homepage/_latest:"~postCount %}
    {% set latest = craft.entries.section('blog').limit(postCount) %}
    ...
{% endcache %}
</code></pre>

CC BY-SA 3.0
2014-11-21T17:48:26.800Z
2014-11-21T17:48:26.800Z
Brandon Kelly
<p>Im using a pretty standard method for calling for entries, but with one small caveat in that I'm setting the limit inside a variable which is passed through to an include</p>

<p>so my index.twig file is like so</p>

<pre><code>{% include 'homepage/_latest' with {'postCount' : 9} %}
</code></pre>

<p>and my <code>homepage/_latest</code> file has the following</p>

<pre><code>{% cache %}
{% set latest = craft.entries.section('blog').limit(postCount ? postCount : 12) %}

&lt;div class="entries entries--latest"&gt;

    {% for entry in latest %}

    {% include 'blocks/_entry-item-latest' %}

    {% endfor %}

&lt;/div&gt;

{% endcache %}
</code></pre>

<p>Is that variable the issue for me/ I save a post and it doesnt know up on the homepage. I had it setup to invalidate every 15 minutes, but we put out 3-4 posts a day so theres no real need to invalidate that content every 15 minutes</p>

CC BY-SA 3.0
2014-11-20T21:18:48.490Z
I'm pretty sure that wouldn't affect it. What happens if you remove it as a test.
Brad Bell
<cache>
Cache Not Invalidating
# Cache Not Invalidating

(Asked by: username_0 on 2014-11-20)

Im using a pretty standard method for calling for entries, but with one small caveat in that I'm setting the limit inside a variable which is passed through to an include
so my index.twig file is like so
{% include 'homepage/_latest' with {'postCount' : 9} %}

and my homepage/_latest file has the following
{% cache %}
{% set latest = craft.entries.section('blog').limit(postCount ? postCount : 12) %}



    {% for entry in latest %}

    {% include 'blocks/_entry-item-latest' %}

    {% endfor %}



{% endcache %}

Is that variable the issue for me/ I save a post and it doesnt know up on the homepage. I had it setup to invalidate every 15 minutes, but we put out 3-4 posts a day so theres no real need to invalidate that content every 15 minutes

**Tags:** cache

> **Comments:**
> **username_1**: I'm pretty sure that wouldn't affect it. What happens if you remove it as a test.  

---

## 1 answers

### Answer by username_2 on 2014-11-21. Score: 2 | Accepted answer

If I understand you correctly, you’d basically need it to store separate caches depending on the limit.
The way to do that would be to set a custom key on the {% cache %} tag with the using key param:
{% if postCount is not defined or not postCount %}
    {% set postCount = 12 %}
{% endif %}

{% cache using key "homepage/_latest:"~postCount %}
    {% set latest = craft.entries.section('blog').limit(postCount) %}
    ...
{% endcache %}


---

