3

Please assume that there is a PHP CMS that retrieves content according to IDs from database.

So every time you visit this website it interacts with Database and Processes the PHP request.

Can Nginx or Varnish cache and store a page after user visited that page? So next time if any user visits that page it will load from the cache.

pkhamre
  • 6,120
  • 3
  • 17
  • 27
Zim3r
  • 1,454
  • 5
  • 24
  • 45
  • 3
    For a per-user or a per-site cache? Both are possible. – pkhamre Oct 22 '12 at 09:49
  • 1
    +1 Thanks, actually I don't understand differences between per-user and per-site cache. I mean if first user loaded a page, next user would load that page faster. does this save files as html or something? – Zim3r Oct 22 '12 at 09:59
  • 2
    You need to understand the difference. A per-user cache simply means that pages is cached, so when user A hits page A it loads from the backend, but the next time user A hits page A its from the cache. A per-site cache means that when user A hits page A it loads from the backend, and the next time user B hits page A it loads from the cache. – pkhamre Oct 22 '12 at 10:04
  • 2
    Basically, does your users get different content or does everyone see the same content? – pkhamre Oct 22 '12 at 10:05
  • Thanks, In my case it's per-site cache. and everyone sees the same content. – Zim3r Oct 22 '12 at 10:26
  • 1
    Then running Varnish with the default configuration will get you started out with caching. – pkhamre Oct 22 '12 at 10:28
  • Thanks, does Varnish saves the cached page on the disk? can I choose where to save it? – Zim3r Oct 22 '12 at 10:32
  • 1
    You can use either mmap(2) or malloc(3). While mmap will map a specified file to memory, malloc will use the regular OS virtual memory. – pkhamre Oct 22 '12 at 10:40
  • Remember that Varnish is an in-memory cache, and not a disk cache. – pkhamre Oct 22 '12 at 10:41
  • Really Thanks pkhamre, I Think if I run out of physical memory I must use malloc. In the mean while I was checking varnish configuration and I didn't see any option to flush the caches. Is this functionality possible? – Zim3r Oct 22 '12 at 10:52
  • Yes, it is possible. Refer to the Varnish Documentation (https://www.varnish-cache.org/docs/3.0/) for information on this and how to configure Varnish. I will post this in an answer below so you can accept if you want. – pkhamre Oct 22 '12 at 10:53

1 Answers1

1

Varnish is capable of caching content infront of your CMS. You will get a conservative caching policy with the default configuration so I suggest you start with this and work your way up from there.

You should also know that Varnish is not a disk cache, but an in-memory cache.

pkhamre
  • 6,120
  • 3
  • 17
  • 27