longdesc.length > 0 ? longdesc : nil
end
- #Calculate Election Results
+ #Calculate results if not in memcache
def results
+ # Assignment is intentional
+ if Cache and c = Cache.get("election_results:#{id}:#{self.votes.length}")
+ @plurality_result = c['plurality']
+ @approval_result = c['approval']
+ @condorcet_result = c['condorcet']
+ @ssd_result = c['ssd']
+ @borda_result = c['borda']
+ return c
+ elsif Cache
+ # memcache is available, but missed.
+ results = self.results!
+ Cache.set("election_results:#{id}:#{self.votes.length}", results)
+ return results
+ else
+ return self.results!
+ end
+ end
+
+ #Always Calculate Election Results
+ def results!
# initalize the tallies to empty arrays
preference_tally = Array.new
plurality_tally = Array.new
names
end
-
end
# Settings specified here will take precedence over those in config/environment.rb
-
+#disable memcache
+Cache=nil
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
# Settings specified here will take precedence over those in config/environment.rb
-
+#
+#Enable memcache
+require('memcache')
+Cache=MemCache.new('localhost', :compression => true)
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Settings specified here will take precedence over those in config/environment.rb
-
+#disable memcache
+Cache=nil
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped