WordPress.org

Ready to get started?Download WordPress

Forums

WP_Cache works in 2.8.4? (4 posts)

  1. mptre
    Member
    Posted 4 years ago #

    Hi WordPress lovers!
    I'm just curious, is the WP_Cache class and its functions still working in 2.8.4? I'm creating a simple function for my theme, used for retreiving attachments. The function wp_cache_add returns true and the cache is there (saw it using var_dump()). But on every page-load the cache disappears, even if I define the cache-time to 1800 (half an hour). So is WP_Cache still working or not?

    <br />
    <?php<br />
    function mytheme_attachment($post_id = NULL) {<br />
        global $post;<br />
        $post_id = (empty($post_id)) ? $post->ID : $post_id;</p>
    <p>    if ($cache = wp_cache_get('mytheme_attachment_' . $post_id, 'mytheme')) {<br />
            return $cache;<br />
        } else {<br />
            // Do something clever.</p>
    <p>        wp_cache_set('mytheme_attachment_' . $post_id, $data, 'mytheme', 1800);</p>
    <p>        return $data;<br />
        }<br />
    }<br />
    ?><br />

    Edit: someone seems to have the same problem.

  2. ioni
    Member
    Posted 4 years ago #

  3. digitalnature
    Member
    Posted 4 years ago #

    I have the same problem :(

  4. damniel
    Member
    Posted 4 years ago #

    Since WP 2.5, WP_Cache doesn't support persistent cache across page views by default. To do this with object based cache you need to implement something like batcache with memcached. Checkout this great description on the wphackers mailing list .

    Depending on how you need to cache data it may be possible to use the new Transients api which is available as of 2.8 .

Topic Closed

This topic has been closed to new replies.

About this Topic