[LP8.6.3/IIS] Cache not working?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[LP8.6.3/IIS] Cache not working?

Jon Harris
Hi

I am working on a ecommerce site where we get stock levels via a web service call. I am using include_URL, posting the parameters and getting XML back for each product code and current stock level. The data is not that dynamic, so I want to speed things up by not having to get the data each time a product page is displayed. The webservice does not allow the product code to be passed, it will only return all products.

On the product page, an ajax call gets the current stock level and displays it, a couple of secs after the page loads. The actual code is working fine. The ajax page looks like this:

// getstocklevel.lasso
var('pcode') = action_param('pcode') ;

Cache(-Name='ProductCache', -expires=600) ;

var('theproducts') = (map) ;

var('endpoint') = "http://<the_endpoint>" ;
var('service') = "/webservices/GETALLSTORESTOCK" ;
var('params') = array('SinceDate' ='2015-01-01T00:00:00', 'User' = '', 'Password' = '') ;
var('rawdata') = string(include_url($endpoint + $service, -postPARAMS=$params)) ;

// cast to xml
var('xmldata') = xml( var('rawdata') ) ;

// xpaths for each field
var('xproductsno') = '/DataSet/StoreStock[*]/ProductNo' ;
var('xquantities') = '/DataSet/StoreStock[*]/Quantity' ;

var('productnos') = XML_Extract(-XML=$xmldata, $xproductsno)  ;
var('quantities') = XML_Extract(-XML=$xmldata, $xquantities)  ;

iterate($productnos, var('xthisProductNo') ) ;
        var('thisProductNo') = var('xthisproductNo')->contents ;
        var('thisProductNo')->trim ;
        var('thisQuantity') = var('quantities')->get(loop_count)->contents ;
        // add to the map
        $theproducts->insert($thisproductno = $thisQuantity) ;
/iterate ;

/cache ;

var('returnVal') = $theproducts->find($pcode) ;
if($returnVal) ;
        $returnVal ;
else ;
        "ERROR" ;
/if ;

This code works once with the cache tags, then fails. And without the cache tags its fine. Checking in lassoadmin the cache, reads:

ProductCache_global

Value Size 0 Chars
Value Type String
Store Count 1
Fetch Count 1
Efficiency 0%

In other words, the code fails because the cache is empty and returns nothing.

(I tried changing from site to global caches, but no difference)

My alternative method is to import the data into a mysql table and run a scheduled task to keep reading in the data, but I would like to understand what is going on here.

Any pointers appreciated.

Jon Harris



#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: [LP8.6.3/IIS] Cache not working?

Peter D Bethke
Hi Jon,

Actually, I think the page is failing because the map variable $theproducts is instantiated inside the cache block. So, the first time it executes, its not cached and its executed - the second time - its not instantiated because the cache returns simply string values. The cache does not instantiate variables or execute code.

Typically a cache is used to re-display a rendered (string) set of data. If there are variables inside the cache block, they’ll most likely have been set external to the cache and then re-displayed as a static string. Or, at the least, not referenced outside the cache block further down the page.

So, at the very least, make sure you set variables that are referenced outside the cache block before the cache block is invoked.

You might also get a lot of this accomplished using global session variables or something similar.

Peter


> On Aug 19, 2015, at 3:52 AM, Jon Harris <[hidden email]> wrote:
>
> Hi
>
> I am working on a ecommerce site where we get stock levels via a web service call. I am using include_URL, posting the parameters and getting XML back for each product code and current stock level. The data is not that dynamic, so I want to speed things up by not having to get the data each time a product page is displayed. The webservice does not allow the product code to be passed, it will only return all products.
>
> On the product page, an ajax call gets the current stock level and displays it, a couple of secs after the page loads. The actual code is working fine. The ajax page looks like this:
>
> // getstocklevel.lasso
> var('pcode') = action_param('pcode') ;
>
> Cache(-Name='ProductCache', -expires=600) ;
>
> var('theproducts') = (map) ;
>
> var('endpoint') = "http://<the_endpoint>" ;
> var('service') = "/webservices/GETALLSTORESTOCK" ;
> var('params') = array('SinceDate' ='2015-01-01T00:00:00', 'User' = '', 'Password' = '') ;
> var('rawdata') = string(include_url($endpoint + $service, -postPARAMS=$params)) ;
>
> // cast to xml
> var('xmldata') = xml( var('rawdata') ) ;
>
> // xpaths for each field
> var('xproductsno') = '/DataSet/StoreStock[*]/ProductNo' ;
> var('xquantities') = '/DataSet/StoreStock[*]/Quantity' ;
>
> var('productnos') = XML_Extract(-XML=$xmldata, $xproductsno)  ;
> var('quantities') = XML_Extract(-XML=$xmldata, $xquantities)  ;
>
> iterate($productnos, var('xthisProductNo') ) ;
> var('thisProductNo') = var('xthisproductNo')->contents ;
> var('thisProductNo')->trim ;
> var('thisQuantity') = var('quantities')->get(loop_count)->contents ;
> // add to the map
> $theproducts->insert($thisproductno = $thisQuantity) ;
> /iterate ;
>
> /cache ;
>
> var('returnVal') = $theproducts->find($pcode) ;
> if($returnVal) ;
> $returnVal ;
> else ;
> "ERROR" ;
> /if ;
>
> This code works once with the cache tags, then fails. And without the cache tags its fine. Checking in lassoadmin the cache, reads:
>
> ProductCache_global
>
> Value Size 0 Chars
> Value Type String
> Store Count 1
> Fetch Count 1
> Efficiency 0%
>
> In other words, the code fails because the cache is empty and returns nothing.
>
> (I tried changing from site to global caches, but no difference)
>
> My alternative method is to import the data into a mysql table and run a scheduled task to keep reading in the data, but I would like to understand what is going on here.
>
> Any pointers appreciated.
>
> Jon Harris
>
>
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>  the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>