You are here:  » Presales question: caching


Presales question: caching

Submitted by formmailer on Thu, 2007-10-18 21:26 in

Hi!

From what I've seen is Magic Parser exactly what I need, but I have 2 questions:

1. Does Magic Parser support caching or is the feed download everytime (and can the caching period be changed if needed?

2. Does Magic Parser support multiple feeds on one page without any "re-declare function problems" (I believe I saw on the forum it does)

Thanks in advance!

- Jasper

Submitted by support on Thu, 2007-10-18 21:37

Hello Jasper,

The script doesn't perform any caching, however it is something that is quite easy to setup. I've posted instructions for my favoured way of doing this in the following thread:

http://www.magicparser.com/node/136

Regarding multiple use on a single page - that's no problem. The redclaration errors you may have seen in the forum have occured where users have included MagicParser.php more than once, which you don't need to do. Once required(), you can then have multiple calls to MagicParser_parse() throughout your script.

Hope this helps!
Cheers,
David.

Submitted by formmailer on Fri, 2007-10-19 08:06

Hi David,

Thanks for your prompt reply.
I've got an additional question that came up:

I want to use Magic Parser for productfeeds, but I only want to display a limited number of random items. In another script I used before (but I didn't really like), I was able to achieve this by the shuffle($ARRAY) function. Is something like this possible with Magic Parser as well?

Thanks in advance!

Kind regards,
Jasper

Submitted by support on Fri, 2007-10-19 08:28

Hello Jasper,

That is reasonably straight forward to do, but it does of course entail reading the entire feed into memory first, and then choosing random products. This shouldn't be a problem if your other script didn't have any memory issues doing this, but for a product feed of many thousands of records it could become a problem, so something to be aware of.

What you do, is rather than display / use each record within your myRecordHandler() function, you instead add the record to a global array. After the parse has finished, you can then do exactly the same as you mention - shuffle($ARRAY), and then pick off the first n items. For example:

<?php
  
require("MagicParser.php");
  
$records = array(); // global array of records to pick from later
  
function myRecordHandler($record)
  {
    global 
$records;
    
$records[] = $record;
  }
  
MagicParser_parse(...);
  
shuffle($records);
  
// now you pick off as many random records as you require....
?>

Since you mentioned product feeds - were you aware of my other script - Price Tapestry?, which uses Magic Parser to load product feeds into MySQL to allow you to create a price comparison site. If you buy Magic Parser and would like to try Price Tapestry in the future simply let me know and you would only need to pay the difference...

Hope this helps!
Cheers,
David.