Welcome Guest, Not a member yet? Register   Sign In
Caching every 1 second
#7

[eluser]sn4k3[/eluser]
[quote author="kevinprince" date="1263714952"]Better solution is:

Cache the returned db object in memcache etc
When the object is returned include the expiry time
Use this expiry time to build the view and use frontend code along with validation of the bid method to make sure you cant bid if the expiry based.

If you want you can cache the view and use javascript to evaluate if the auction has closed.[/quote]

Im not understanding very well what that mean
in that part:

Quote:Use this expiry time to build the view and use frontend code along with validation of the bid method to make sure you cant bid if the expiry based.

If you want you can cache the view and use javascript to evaluate if the auction has closed.

i current have that in my view: (Fragment only)

Code:
< script type = "text/javascript" >
var liveids = <?php echo json_encode($this->Auction_model->AuctionsToIds($auctions)); ?>;
function joinArray(ar)
{
    var b;
    b = ar.join(",");
    return(b);
}
function updateAuctions()
{
    jQuery.ajax({
            type: "POST",
            url: base_url+"Api/GetAuctions",
            data: ({ ids : '['+joinArray(liveids)+']' }),
            timeout: 1000,
            /*contentType: "application/json; charset=utf-8",*/
            dataType: "json",
            success: function(message) {
                for (var i in message)
                {
                    var oldcurrentuser = jQuery("#AICurrentuser"+message[i].id).text();
                    if(message[i].closed == 1){
                        jQuery("#AICurrenttime"+message[i].id).text('Terminou');
                        jQuery("#AICurrenttime"+message[i].id).css('color', 'red');
                        jQuery("#AIBid"+message[i].id).fadeOut('slow');
                        jQuery.jGrowl('Vencedor: '+message[i].currentuser+'<br />Pre&ccedil;o de mercado: <strong>'+message[i].realprice+' &euro;</strong><br />Pre&ccedil;o Final: <strong>'+message[i].currentprice+' &euro;</strong><br />Poupou: <strong>'
                                    +message[i].saveprice+' &euro;</strong>',
                            { header: 'Leil&atilde;o #'+message[i].id+' Terminado: '+message[i].name,
                            sticky: true, glue: 'before', position: 'top-left' });
                        liveids.splice(i, 1);
                    }else{
                        if(message[i].standby == 1)
                            jQuery("#AICurrenttime"+message[i].id).text('Suspenso');
                        else
                            jQuery("#AICurrenttime"+message[i].id).text(message[i].currenttime);
                        jQuery("#AICurrentprice"+message[i].id).html(message[i].currentprice+' &euro;');
                        jQuery("#AICurrentuser"+message[i].id).text(message[i].currentuser);
                        jQuery("#AISeconduser"+message[i].id).text(message[i].seconduser);
                        jQuery("#AIThirduser"+message[i].id).text(message[i].thirduser);
                        if(message[i].currentuser == myusername)
                            jQuery("#AICurrentuser"+message[i].id).css('color', 'red');
                        else
                            jQuery("#AICurrentuser"+message[i].id).css('color', '#666');
                        if(message[i].seconduser == myusername)
                        {
                            jQuery("#AISeconduser"+message[i].id).css('color', 'red');
                            if(message[i].currentuser != myusername && oldcurrentuser == myusername)
                                jQuery.jGrowl("Um utilizador licitou por cima da sua licita&ccedil;&atilde;o!<br />Utilizador: <strong>"+message[i].currentuser+"</strong><br /><a >Licitar</a>",
                                              { header: message.name, life: 7500, glue: 'before' });
                        }
                        else
                            jQuery("#AISeconduser"+message[i].id).css('color', '#666');
                        if(message[i].thirduser == myusername)
                            jQuery("#AIThirduser"+message[i].id).css('color', 'red');
                        else
                            jQuery("#AIThirduser"+message[i].id).css('color', '#666');
                    }
                }
                //jQuery("#cDateHour").text(message.d);
            }
    });
    setTimeout('updateAuctions()',1000);
}
function bidAuction(itemid)
{
    jQuery.ajax({
            type: "POST",
            url: base_url+"Api/BidAuction",
            data: ({ id : itemid }),
            dataType: "json",
            success: function(message) {
                if(message == -2) // Error in make changes
                    jQuery.jGrowl("Erro ao tentar proceder a sua licita&ccedil;&atilde;o!<br />Se este problema continuar fa&ccedil;a refresh &agrave; p&aacute;gina.", { header: 'Erro', life: 10000, glue: 'before' });
                if(message == -1) // Logout
                    document.location=base_url+'Utilizador/Entrar';
                else if(message == 0) // No Bids
                    document.location=base_url+'Utilizador/Comprar';
                else // OK
                {
                    jQuery("#AIBid"+itemid).show('pulsate');
                    jQuery.jGrowl("A sua licita&ccedil;&atilde;o foi aceite, fique atento.", { header: message.name, life: 7500, glue: 'before' });
                }
            }
    });
}
    jQuery(document).ready(function() {
        setTimeout('updateAuctions()',1000);
    });
&lt;/ script&gt;


Messages In This Thread
Caching every 1 second - by El Forum - 01-16-2010, 03:12 PM
Caching every 1 second - by El Forum - 01-16-2010, 04:56 PM
Caching every 1 second - by El Forum - 01-16-2010, 05:21 PM
Caching every 1 second - by El Forum - 01-16-2010, 05:39 PM
Caching every 1 second - by El Forum - 01-16-2010, 06:03 PM
Caching every 1 second - by El Forum - 01-16-2010, 07:55 PM
Caching every 1 second - by El Forum - 01-17-2010, 08:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB