This is a very basic example of using memcache + PHP
Use at your own peril
$memcache = new Memcache; $memcache->connect("127.0.0.1"); $sql = "select * from some_huge_table where tx_date <= now()-365 limit 0, 5000"; $key = md5($sql); $query = $memcache->get($key); //the query isnt in the cache if ($query == null) { $query = $this->db->query($sql); $query = $query->result(); //put it in the cache $memcache->set($key,$query,0,600);//10 minute expiry } if (count($query) > 0) { //do something with $query } |
This example loads memcached, looks for a key, and if its not there, stores it. SIMPLE
****UPDATE****
Today while going through CI framework, I realized that CI can do its own query caching, albeit to disk. For more info on CI query caching, look go here
To change this to memcached caching should be a cinch, and indeed, it is. Head over here to see how.
So without having to change a single line of code in your application, you can take full advantage of memcached for caching query results
Memcache is a very simple caching system that uses memory to store objects. As you may already know, memory is faster to read than hard drive. A site will take a lot less time to read a database result cached in memory. To make the best use of memcache, you should install the memcached module. For this post we used Ubuntu Server 10.04, but all commands should work on most Ubuntu editions.
I have chosen to use memcached, rather than memcache. Have a look here to view a comparison
First, install the memcached package, php-pear (required for pecl), php5-dev (required for phpize) and libmemcached-dev
sudo apt-get install memcached sudo apt-get install php-pear sudo apt-get install php5-dev sudo apt-get install libmemcached-dev |
next, install memcached using pecl
sudo pecl install Memcache |
Also, we need to enable the memcache extension on php:
sudo echo "extension=memcache.so" > /etc/php5/apache2/conf.d/memcache.ini |
Add the following line to your php.ini file.
memcache.hash_strategy="consistent" |
You can add it anywhere in the file.
Next you need to start an instance of memcache, you can start a daemon with the following command:
memcached -d -m 2048 -l 10.0.0.40 -p 11211 |
If you are only using a single server, then you only need to include this line to your site’s settings.php file.
$conf['cache_inc'] = '/sites/all/modules/memcache/memcache.inc'; |
The final step is to restart apache and then switch your site back online if it was offline.
The AJAX Libraries API provides your applications with stable, reliable, high speed, globally available access to all of the most popular, open source JavaScript libraries. Your application can use Google’s very flexible loader google.load() or direct, path based access to the scripts.
Because Google has edge servers in most countries, your users will be loading the javascript from a local server, rather than your webserver.
Warning: You need your own API key. In the example below, replace “INSERT-YOUR-KEY” with your own, unique key. Without your own key, these examples won’t work.
<script type="text/javascript" src="http://www.google.com/jsapi?key=INSERT-YOUR-KEY"></script> |
Next, you load the libraries is by using google.load() to name a library and your prefered version. E.g.:
google.load("jquery", "1.4.2"); google.load("jqueryui", "1.8.2"); |
You can also link directly to the source files like this
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> |
for more information see, http://code.google.com/apis/ajaxlibs/documentation/

Categories
Tag Cloud
Blog RSS
Comments RSS
Last 50 Posts
Back
Void « Default
Life
Earth
Wind
Water
Fire
Light 