How does memcache store data?

  Memcached's APIs provide a giant hash table distributed across multiple machines. When the table is full, subsequent inserts cause older data to be purged in least recently used (LRU) order.

  The servers keep the values in RAM; if a server runs out of RAM, it discards the oldest values. Therefore, clients must treat Memcached as a transitory cache; they cannot assume that data stored in Memcached is still there when they need it.

Difference between memcache and varnish?

  Memcached can be used as an in-memory, distributed back-end for your application cache.
  Varnish can be used as a reverse proxy to externally cache HTTP requests.

  It seems to me that Varnish is behind the web server, caching web pages and doesn't require change in code, just configuration.
  On the other side, Memcached is general purpose caching system and mostly used to cache result from database and does require change in get method (first cache lookup).

Creating custom hooks in Drupal?

1) Alter hooks
   a common way to edit the contents of a particular object or variable by settings     variables in the hook by reference, typically by using drupal_alter()

2) Intercepting hooks
  Allowing external modules to perform actions during the execution, cannot get variables by reference, typically by using module_invoke_all(), module_invoke()

a) Simple invoking:
module_invoke_all() => Calling all modules implementing the hook

Drupal Template Structure

|->  HTML Head
|->  Page
      |-> Node
              |-> Field
              |-> Field
              |->Node Links
              |->Comment Wrapper
                    |-> Comment
                    |-> Comment
                    |-> Comment
      |-> Region
            |-> Block
            |-> Block

Preprocess Functions (theme_hook) Drupal

Allow one module to alter the variable used by another module when it call a theme hook.

  -> Process variables for node.tpl.php

   -> Process variables for page.tpl.php

[module]_preprocess_[theme hookname]  (&$variables)

multi-hook preprocess functions
[module]_preprocess (&$variables, $hook)

Order of preprocess execution
All Preprocess functions run before all process functions