How does DreamFactory handle caching?


I am a bit curious how DF handles caching and when does it expire the cache? Is it explained somewhere in the docs?


Prior to the 1.7 release, the caching was a bit of a mess. There were three different caches doing pretty much the same thing.

For the 1.7 version, we consolidated these caches into a single “app store”. This is the main, and only, cache used by the DSP now. It is a file based cache and by default, lives in /tmp/.dsp. There is also another tiny cache in /tmp/.kc used to keep environment information that is global to the machine.

In addition, we added support for memcached. To enable use of memcached, you must do the following:

  1. Install memcached if not already installed: $ sudo apt-get install memcached
  2. Install the PHP memcached extension: $ sudo apt-get install php5-memcached
  3. Enable the module: $ sudo php5enmod memcached
  4. If you’re running php5-fpm, restart it: $ sudo service php5-fpm restart
  5. Copy the config/databases/memcache.config.php-dist file to config/memcache.config.php and change to match your setup.
  6. Delete the old cache directories in /tmp: $ sudo rm -rf /tmp/.dsp/ /tmp/.kc/
  7. Restart your web server

At this point, when the system starts up, it will discover the memcached server and use it instead of the /tmp/.dsp file location. Log in to your DSP and then look in the /tmp directory. If there is no /tmp/.dsp directory, then memcached is being used.

We will offer more caching options in the future. Hope that helps!


okay i did the first two steps which i ran from the /apps/dreamfactory directory.

The sudo php5enmod memcached command returns “Command not found”

That is the server details in amazon EC2 “This security group was generated by AWS Marketplace and is based on recommended settings for DreamFactory powered by Bitnami version 1.5.9-1 on Ubuntu 12.04.4 provided by Bitnami”

After googling for a while it seems that this version of Ubuntu doesn’t have it installed

any Idea how I can resolve that issue?

many thanks


I still can’t get this to work with my setup. I would really appreciate any help!!

Thank you

Can't save object with nil foreign keys

That’s ok, the php5enmod tool only makes symlinks. You can do it manually:

  • Make sure you have installed the memcached PHP extension (sudo apt-get install php5-memcached). This creates the /etc/php5/mods-available/memcached.ini file. Check it and make sure it looks kosher.

  • Depending on which versions of PHP you have installed, there will be a corresponding directory created under /etc/php5. For php5-cli, the directory is /etc/php5/cli. For PHP FPM, the directory is /etc/php5/fpm, etc. Beneath each of these directories is another directory called conf.d (i.e. /etc/php5/cli/conf.d):

$ dir /etc/php5/
total 36K
drwxr-xr-x   7 root root 4.0K Aug 19 16:34 .
drwxr-xr-x 195 root root  12K Sep  9 13:46 ..
drwxr-xr-x   3 root root 4.0K Aug 19 13:14 cgi                                        <---- php5-cgi
drwxr-xr-x   3 root root 4.0K Aug 19 16:34 cli                                         <---- php5-cli
drwxr-xr-x   4 root root 4.0K Aug 19 16:34 fpm                                       <---- php5-fpm
drwxr-xr-x   2 root root 4.0K Aug 21 16:30 mods-available                     <---- all installed extensions
-rw-r--r--   1 root root   70 Jan  8  2014 mods-available/memcached.ini  <---- The memcached config file
  • For each of the installed PHP5 runtimes (i.e. cgi, cli, fpm, etc.) in which you wish to have memcached available; create a symlink from /etc/php5/mods-available/memcached.ini into the conf.d directory of that runtime:
$ cd /etc/php5/fpm/conf.d
$ ln -s ../../mods-available/memcached.ini 20-memcached.ini
$ cd ../../cli/conf.d
$ ln -s ../../mods-available/memcached.ini 20-memcached.ini
```<br/>I doubt you're using CGI so I didn't show that in the example. The **20-** priority in front of the file name is inserted/managed by the `php5enmod` and `php5dismod` tools. I put the **20-** in the symlink name so it can be removed with php5dismod, should you find that it is working on your box.

* Restart your server(s):<br/>

sudo service apache2 restart sudo service nginx restart
$ sudo service php5-fpm restart

* Check if it's loaded:<br/>

$ php -i | grep memcached
memcached support => enabled
libmemcached version => 1.0.18

At this point, you should be good to go. To fully ensure that the **memcached** stuff is being used, delete any caches that the DSP may have created:

$ sudo rm -rf /path/to/your/dsp/storage/.private/ /tmp/.dsp* /tmp/.dreamfactory* /tmp/.kc

These are all the places where the DSP caches, or has cached in the past, data.

Fire up your browser and go to your DSP, click around and close your browser. Now, look in the directories mentioned above. They shouldn't be there. If they are there, then your memcache isn't working. If they are **not** there, your memcache is working fine.

Let me know if you still need help.


How do i know which PHP5 runtime i am using?


What’s in your /etc/php5 directory?


cli conf.d fpm mods-available


Looks like you’re running an FPM system. Try one of these:

Stand-Alone Installations

  1. Make sure you that the file memcached.ini is in your /etc/php5/mods-available directory

  2. Perform the following:

$ cd /etc/php5/fpm/conf.d
$ sudo ln -s ../../mods-available/memcached.ini 20-memcached.ini
$ cd ../../cli/conf.d
$ sudo ln -s ../../mods-available/memcached.ini 20-memcached.ini
$ sudo service php5-fpm restart && sudo service apache2 restart

You may safely ignore any “link exists” error during above the ln -s commands. Also, if you’re running nginx instead of apache2, substitute nginx with apache2 in the service restart command above.

Bitnami Stack Installations

Bitnami stack installations are a bit different. They install a private copy of apache and php under the initial Bitnami installation directory. I know you’re on Ubuntu, but not sure if you installed the Bitnami stack.

Until Bitnami includes the memcached extension into their distribution (next release), you will not be able to use memcached.