Special Cookie On Sign In / Add To Cart

Hello,

So after playing a bit with Nginx caching I realised that it would be farily hard to implement HTTP caching, where as php caching is fairly easy. So this kind of made me wonder how I could implement this, because I am struggling with one thing which is that whenever a user does something (like adding something to their cart or signing in) it needs to server fresh content.f

So my idea was to rewrite the login function and the add to cart function and add a line which will set a cookie, something like, unique_content. Where can I find these lines, and can anyone perhaps guide me through this process?

Sincerely Yours,

// EDIT

This doesn't just apply for the add to cart and sign in function but also for the wishlist and compare functions

// EDIT 2

Or we can just disable the sid_customer given on the first pageload and server it whenever someone does one of the following actions

Hello,

Please take a look at our official free Varnish cache add-on: https://github.com/cscart/full-page-cache-addon

It implements HTTP caching using the Varnish. However, you may modify it to fit your needs.

Hello,

Please take a look at our official free Varnish cache add-on: https://github.com/cscart/full-page-cache-addon

It implements HTTP caching using the Varnish. However, you may modify it to fit your needs.

Hello,

The problem with Varnish is that it takes very long to set up properly whilst in Nginx I only have to add about 10 lines to do the same thing as Varnish. Furthermore, I also have a hosting contract which states that I cannot use unofficial ubuntu packages, so it needs to be in the Ubuntu repository. And since varnish 4.1.x is not supported it means that I cannot use it.

So basically I can only use this solution......

But thanks for the quick reply anyways!

Proper configuring of Nginx HTTP caching will take much more time than doing so in Varnish, just because of its syntax simplicity.

Also, our Varnish caching has block-level cache control feature:

  • Guests receive the whole page from cache. The vast majority of visitors are just guests, and they don't actually impact server load at all.
  • Guests with session started receive the whole page from cache, except for session-dependent blocks like "Cart content" or "My account". Session starts, for example, when user adds product to cart or to wishlist.

Authenticated users aren't affected by HTTP caching at all, because there are too many possible factors that invalidate cache for them (like usergroup-based promotions and so on).

Hope this information helps you.

It would be really great if you could implement Nginx support for the add-on and share it with the community :)

The add-on itself is free and open-source, but we haven't received any pull requests for now.

It would be really great if you could implement Nginx support for the add-on and share it with the community :)

The add-on itself is free and open-source, but we haven't received any pull requests for now.

Hello,

Well, it isnt really an addon, its just a syntax which will deliver complete prerendered pages (load time is approx 500 ms on first load). I just need to figure out how to exclude customers who have done an action on the store, but whenever that's done I will do that for sure! Any support regarding this is appreciated though :grin:

If any of you guys have an idea on how to implement the followi, that'd be great:

So the basic problem as of right now is that nginx needs to detect whether you are a normal user or a user which has done some sort of action. Therefore I have tried many things, like embedding javascript which will add a cookie whenever you click on a button which has the class add-cookie. This of course is a way to annoying method of doing this. Therefore it would be great if someone could make some sort of addon which will add a cookie whenever an user does such action. e.g.

Whenever I click the add_to_cart button, a cookie called 'unique_content' should be added. This should be somehow embedded in the add_to_cart function, I just havent found a proper way to do this. The same applies for every other button regarding this. E.g.:

- wishlist

- comparison

- buy together

- login / logout

- etc.

If anyone would have some indication on how to do this, please contact me!

//EDIT

Proper configuring of Nginx HTTP caching will take much more time than doing so in Varnish, just because of its syntax simplicity.

I have to say that I have to disagree with this point of yours, it really depends on how you want to use your resources. Yes you could make an overkill setup that will make it go to 450ms, but it really is just not worth it.

This would require you to setup some sort of caching server in front of the origin server which would validate the request to decide whether it is a hit or miss.

My script on the other hand is 9 lines of code that will be embedded into the regular nginx script that is provided by cs-cart. Which for sure is less than your entire varnish configuration!

Furthermore I'd also like to talk about your statement about varnish caching every block.

First of all, nginx has many types of caching. It for example has fastcgi caching (aka php caching), full page caching and many more things. Therefore the more frequent php requests are being cached as well.

Secondly, nginx is faster in most scenerios as it has the ability to pass requests through sockets, and not through an http port, which also improves the speed by a ton!

- add to cart

use the add_to_cart hook in the fn_add_product_to_cart function (app/functions/fn.cart.php)

- wishlist

use the pre_add_to_wishlist hook in the fn_add_product_to_cart function (app/addons/wishlist/controllers/frontend/wishlist.php)

- comparison

use the product_features.post.php controller in your addon with the "add_product" mode

- buy together

not clear

- login / logout

use the login_user_post hook in the fn_login_user function (app/functions/fn.users.php)

- add to cart

use the add_to_cart hook in the fn_add_product_to_cart function (app/functions/fn.cart.php)

- wishlist

use the pre_add_to_wishlist hook in the fn_add_product_to_cart function (app/addons/wishlist/controllers/frontend/wishlist.php)

- comparison

use the product_features.post.php controller in your addon with the "add_product" mode

- buy together

not clear

- login / logout

use the login_user_post hook in the fn_login_user function (app/functions/fn.users.php)

Thank you so much!

Just to clarify the buy together, the buy together also has an 'add all to cart' button, but for this I was just wondering whether this was a seperate function or just an extended add_to_cart function.

Thank you so much!

Just to clarify the buy together, the buy together also has an 'add all to cart' button, but for this I was just wondering whether this was a seperate function or just an extended add_to_cart function.

Right, the add_to_cart hook can be used here

Hello,

Well, it isnt really an addon, its just a syntax which will deliver complete prerendered pages (load time is approx 500 ms on first load). I just need to figure out how to exclude customers who have done an action on the store, but whenever that's done I will do that for sure! Any support regarding this is appreciated though :grin:

If any of you guys have an idea on how to implement the followi, that'd be great:

So the basic problem as of right now is that nginx needs to detect whether you are a normal user or a user which has done some sort of action. Therefore I have tried many things, like embedding javascript which will add a cookie whenever you click on a button which has the class add-cookie. This of course is a way to annoying method of doing this. Therefore it would be great if someone could make some sort of addon which will add a cookie whenever an user does such action. e.g.

Whenever I click the add_to_cart button, a cookie called 'unique_content' should be added. This should be somehow embedded in the add_to_cart function, I just havent found a proper way to do this. The same applies for every other button regarding this. E.g.:

- wishlist

- comparison

- buy together

- login / logout

- etc.

If anyone would have some indication on how to do this, please contact me!

//EDIT

I have to say that I have to disagree with this point of yours, it really depends on how you want to use your resources. Yes you could make an overkill setup that will make it go to 450ms, but it really is just not worth it.

This would require you to setup some sort of caching server in front of the origin server which would validate the request to decide whether it is a hit or miss.

My script on the other hand is 9 lines of code that will be embedded into the regular nginx script that is provided by cs-cart. Which for sure is less than your entire varnish configuration!

Furthermore I'd also like to talk about your statement about varnish caching every block.

First of all, nginx has many types of caching. It for example has fastcgi caching (aka php caching), full page caching and many more things. Therefore the more frequent php requests are being cached as well.

Secondly, nginx is faster in most scenerios as it has the ability to pass requests through sockets, and not through an http port, which also improves the speed by a ton!

I would like to thanks to you as the solution which you have provided worked for me. As i am rounding the situation earlier.

It would be really great if you could implement Nginx support for the add-on and share it with the community :)

The add-on itself is free and open-source, but we haven't received any pull requests for now.

Okay, I have just posted my results, though it isnt done yet. Feel free to check it out!

http://forum.cs-cart.com/topic/49059-nginx-full-page-caching/


I would like to thanks to you as the solution which you have provided worked for me. As i am rounding the situation earlier.

I have just posted my solution to this problem. Feel free to check it out!

http://forum.cs-cart.com/topic/49059-nginx-full-page-caching/