[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: [ANN] Boogaloo Simple Cache Server 0.1

hemant

10/15/2006 5:42:00 AM

On 10/14/06, Ian Leitch <port001@gmail.com> wrote:
> Hey all,
>
> I've just made the first release of a new project: Boogaloo.
>
> Boogaloo is a very simple cache server that provides persistent and
> temporary caches. You can also use it to house your own custom services.
> It's meant to be very simple to use so that you can concentrate on your
> primary problem.
>
> You'll find it fully documented and even has a few unit tests:
> http://boogaloo.ruby...
> or "sudo gem install boogaloo" if you want to play straight away.
>
> Why?
>
> It started out as a place to cache my rendered Liquid template objects and
> somewhere to store a list of selectors from some CSS files. Later on I
> started using it as a temporary cache for objects that were only relevant to
> specific user in Rails. So instead of keeping the object in the users
> session and forgetting to clear it out later, I can now just stick it in
> Boogaloo and let it expire after a period given. This is very handy for
> multi-step forms etc.
>
> Anyway, I hope someone finds it useful...
>
> Cheers,
> Ian.
>
>

Interesting, so where do you cache the data that clients send you?


--
There was only one Road; that it was like a great river: its springs
were at every doorstep, and every path was its tributary.

4 Answers

Nicholas Frechette

10/15/2006 1:19:00 PM

0

Hi, I'm currently working on a side project which has me store binary
content in memory.
In order to make it's use as transparent as possible, i overloaded the
'require' method to search as well in the memory and this works fine at
the moment. In the same line of thought, I tried changing the way
File.new works to return a StringIO object pointing to my binary data in
memory instead of an ordinary IO object... However, i ran into an
interesting problem. Consider the following code:

class File
alias_method :old_new, :initialize

def initialize(*args)
if args[0] == 'a.txt'
# Do not return a file object, return say, a Hash
Hash.new
else
old_new(*args)
end
end
end

o = File.new('a.txt')
puts "Object is of class: #{o.class}"

This outputs:
Object is of class: File

Obviously. Now, looking further for alternatives, i tried to overload
Class.new. Consider the following code:
class Foo
end

class Bar
end

class Class
alias oldNew new
def new(*args)
print "Creating a new ", self.name, "\n"
if self.name == 'File'
require 'stringio'
StringIO.new('This is a string!','r')
elsif self.name == 'Foo'
Bar.new
else
oldNew(*args)
end
end
end

d = Foo.new
puts "Should be type Foo and is: #{d.class}"
n = File.new('lol.rb','r')
puts "Should be type StringIO and is: #{n.class}"
puts "Content is: #{n.read}"

With a file named lol.rb in my path with the single line of content:
"Hello", this outputted:
Creating a new Foo
Creating a new Bar
Should be type Foo and is: Bar
Should be type StringIO and is: File
Content is: Hello

==========================
Two things here:
Class.new is working as expected with Foo, returning a Bar object. But,
when File.new is called, Class.new is not called as it was for Foo.new!

Any thoughts/help please? I have ran out of ideas... An obvious solution
is to use a different constructor that is not File.new but that would
make it not very elegant.

Thanks and regards.
Nicholas

Sander Land

10/15/2006 1:56:00 PM

0

On 10/15/06, Nicholas Frechette
<nicholas.gravel-frechette@usherbrooke.ca> wrote:
> Consider the following code:
>
> class File
> alias_method :old_new, :initialize
>
> def initialize(*args)
> if args[0] == 'a.txt'
> # Do not return a file object, return say, a Hash
> Hash.new
> else
> old_new(*args)
> end
> end
> end
>
> o = File.new('a.txt')
> puts "Object is of class: #{o.class}"
>
> This outputs:
> Object is of class: File
>
> Any thoughts/help please? I have ran out of ideas... An obvious solution
> is to use a different constructor that is not File.new but that would
> make it not very elegant.

SomeClass#initialize is not SomeClass::new, only the return value of
new decides what the returned object is.
As for overriding Class::new, that's just not necessary and there
probably is a File::new or IO::new that prevents Class::new from being
called.

Try
class File
alias ...
def self.new(*args)
if ...
return {}
else
old_new(*args)
end
end

Ara.T.Howard

10/15/2006 2:38:00 PM

0

David Vallner

10/15/2006 4:45:00 PM

0

Please don't hijack threads, it makes a mess of things. Thanks.

David Vallner