Skip to content

Commit

Permalink
redis handler manually purges pngs
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed Dec 29, 2009
1 parent 78551d0 commit d0cf653
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
23 changes: 18 additions & 5 deletions demos/redis/lib/redis_demo/spark_list.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@ class SparkList
# :limit => 50 # :limit => 50
# :redis => {} # passed to Redis # :redis => {} # passed to Redis
def initialize(options = {}) def initialize(options = {})
@prefix = options[:prefix] || 'plug' @cache_path = options[:cache_path]
@limit = options[:limit] || 50 @prefix = options[:prefix] || 'plug'
@index_key = "#{@prefix}:index" @limit = options[:limit] || 50
@redis = Redis.new(options[:redis] || {}) @index_key = "#{@prefix}:index"
@plug_list = PlugList.new(self) @redis = Redis.new(options[:redis] || {})
@plug_list = PlugList.new(self)
end end


def find(name) def find(name)
Plug.new(self, name) Plug.new(self, name)
end end

def unlink(name)
return if !@cache_path
plug_cache = File.join(@cache_path, "#{name}.png")
File.unlink(plug_cache) if File.exist?(plug_cache)
end
end end


class PlugList class PlugList
Expand Down Expand Up @@ -64,6 +71,7 @@ def add(value)
excess.times { @redis.lpop(name_key) } excess.times { @redis.lpop(name_key) }
end end
self.updated_at = Time.now.utc self.updated_at = Time.now.utc
unlink
end end


def datapoints def datapoints
Expand All @@ -80,11 +88,16 @@ def updated_at=(v)
end end


def delete def delete
unlink
@list.plug_list.delete(self) @list.plug_list.delete(self)
@redis.delete(name_key) @redis.delete(name_key)
@redis.delete(updated_key) @redis.delete(updated_key)
end end


def unlink
@list.unlink(@name)
end

def exists? def exists?
count > 0 count > 0
end end
Expand Down
1 change: 1 addition & 0 deletions demos/redis/sparkplug_redis.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{} {}
end end


config[:cache_path] = File.expand_path(File.join(File.dirname(__FILE__), 'public', 'sparks'))
$redis_list = RedisDemo::SparkList.new(config) $redis_list = RedisDemo::SparkList.new(config)
$handler = RedisDemo::Handler.new($redis_list) $handler = RedisDemo::Handler.new($redis_list)
pub_dir = File.expand_path(File.join(File.dirname(__FILE__), 'public')) pub_dir = File.expand_path(File.join(File.dirname(__FILE__), 'public'))
Expand Down

0 comments on commit d0cf653

Please sign in to comment.