--- /usr/local/bin/mrtg.orig	2008-11-14 05:26:22.000000000 +0000
+++ /usr/local/bin/mrtg	2010-01-31 17:51:53.000000000 +0000
@@ -1,4 +1,5 @@
 #! /usr/local/bin/perl -w
+# vim: tabstop=8 shiftwidth=8
 # -*- mode: cperl -*-
 
 ###################################################################
@@ -15,6 +16,11 @@
 #
 ###################################################################
 my @STARTARGS=($0,@ARGV);
+my $RRDCACHED_ADDRESS = 'unix:/var/run/rrdcached.sock';
+
+# Use the cache daemon
+$ENV{'RRDCACHED_ADDRESS'} = $RRDCACHED_ADDRESS;
+my $updatev = 0;
 
 @main::DEBUG=qw();
 # DEBUG TARGETS
@@ -340,6 +346,7 @@
     if ($cfg{logformat} eq 'rrdtool'){
         debug('base', "Loading RRD support");
 	require 'RRDs.pm';
+	$updatev = ( $RRDs::VERSION >= 1.2 && ! $ENV{'RRDCACHED_ADDRESS'} ) ? 1 : 0;
     }
 
     # set the locale
@@ -850,7 +857,7 @@
         debug('log', "RRDs::update($dotrrd, '$time:$inlast:$outlast')");
         my $start = gettimeofday();
 	my $rrddata;
-	if ( $RRDs::VERSION >= 1.2 ){
+	if ( $updatev ) {
 	    $rrddata=RRDs::updatev($dotrrd, "$time:$inlast:$outlast");
         } else {
             RRDs::update($dotrrd, "$time:$inlast:$outlast");
@@ -859,7 +866,7 @@
         my $e = RRDs::error(); 
         warn "$NOW: ERROR: Cannot update $dotrrd with '$time:$inlast:$outlast' $e\n" if ($e);
 
-	if ( $RRDs::VERSION < 1.2 ){
+	if ( ! $updatev ) {
              # get the rrdtool-processed values back from rrdtool
              # for the threshold checks (we cannot use the fetched data)
 	     $start = gettimeofday();
