How could I cache images that I'm pulling from a magento database through ajax?

Posted by wes on Stack Overflow See other posts from Stack Overflow or by wes
Published on 2010-05-19T02:24:28Z Indexed on 2010/05/19 2:30 UTC
Read the original article Hit count: 242

Filed under:
|
|

Here's script being called through ajax:

<?php

require_once '../app/Mage.php';
umask(0);

/* not Mage::run(); */
Mage::app('default');

$cat_id = ($_POST['cat_id']) ? $_POST['cat_id'] : NULL;

try { 

    $category = new Mage_Catalog_Model_Category();
    $category->load($cat_id);

    $collection = $category->getProductCollection();

    $output = '<ul>';

    foreach ($collection as $product) {

    $cProduct = Mage::getModel('catalog/product');
    $cProduct->load($product->getId());

        $output .= '<li><img id="'.$product->getId().'" src="' . (string)Mage::helper('catalog/image')->init($cProduct, 'small_image')->resize(75) . '" class="thumb" /></li>';
    }

    $output .= '</ul>';

    echo $output;

} catch (Exception $e) {

    echo 'Caught exception: ', $e->getMessage(), "\n";
}

I'm just passing in the Category ID, which I've tacked onto the navigation links, then doing some work to eventually just pass back all product images in that category.

I'm using this on a drag and drop build-a-bracelet type of application, and the amount of images returned is sometimes in the 500s. So it get's pretty held up during transmission, sometimes 10 seconds or so.

I know I'd do good by caching them some way, just not sure how to go about it. Any help is much appreciated.

Thanks.

-Wes

© Stack Overflow or respective owner

Related posts about magento

Related posts about caching