Mailing List Archive

Catalyst::Plugin::Session::Store::File patch to use the Cache::FileCache expiry mechanism
Hi,

here goes the patch that I promised on #dbix-class on December 15. It
makes use of the Cache:FileCache expiry mechanism to handle session
expiry, and thus delete_expired_sessions() works. (And, as a side-effect,
halves the number of cache files: previously "session:id" and
"expires:id" were stored as separate cache entries, now only "session:id"
is stored with the value belonging to "expires:id" as expiry date.)

I followed the techniques used the Catalyst::Plugin::Session::Store::DBI
module, I hope that that module is considered to be OK. (As there are
some marginal cases - eg. what happens when "expires:id" is set, but
"session:id" is not yet set.)

Please review my patch (and apply if you accept it).

norbi
Re: Catalyst::Plugin::Session::Store::File patch to use the Cache::FileCache expiry mechanism [ In reply to ]
On 20 Jan 2009, at 00:26, BUCHMULLER Norbert wrote:
> Please review my patch (and apply if you accept it).

Looks semi-reasonable, but there are no tests for the functionality
change, can you add some to show that expiry now works etc?

I'm also slightly worried about the change to get_session_data:

+ return $cache_obj
+ ? $cache_obj->get_expires_at
+ : undef;

That means (to my reading), return the expiry time, if there is a
cache object, or undef if there isn't - and I think you mean check
the expiry time has not passed - if it has return undef, if it
hasn't, return the object..

I may be _totally_ wrong here, as I'm not familiar with (and haven't
refreshed myself on) the Cache::FileCache interface - but either way,
a comment to note the intention would probably go well here..

Many thanks for the patch however, I'll look forward to a re-submit
with my concerns addressed.

If you have chance, maybe you could stop by #catalyst-dev and get a
commit-bit? Then you can work on this change (and give people a
chance to test it) in a branch until its ready for trunk..

Cheers
t0m


_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev
Re: Catalyst::Plugin::Session::Store::File patch to use the Cache::FileCache expiry mechanism [ In reply to ]
On Tue, 20 Jan 2009 09:42:51 +0000 wrote:

>
> On 20 Jan 2009, at 00:26, BUCHMULLER Norbert wrote:
> > Please review my patch (and apply if you accept it).
>
> Looks semi-reasonable, but there are no tests for the functionality
> change, can you add some to show that expiry now works etc?

Yes, of course. It was late and I was too sleepy and I forgot
it. :-( Also I'll try to write test cases for the
delete_expired_sessions() functionality of ::DBI (and maybe others if
they don't have such a test).

> I'm also slightly worried about the change to get_session_data:
>
> + return $cache_obj
> + ? $cache_obj->get_expires_at
> + : undef;
>
> That means (to my reading), return the expiry time, if there is a
> cache object, or undef if there isn't - and I think you mean check
> the expiry time has not passed - if it has return undef, if it
> hasn't, return the object..

I think that the above code is right, if we accept a few assumptions
(those are the same that are assumed by ::DBI), namely:

* "flash:id" and "session:id" share their expiry time
* "flash:id" is never set before "session:id" is set
* "expires:id" is always set after "session:id", or "expires:id" contains
the same value as $c->session_expires
* "expires:id" is never fetched before setting "session:id"

Cache::Cache::get() returns the data stored in the cache object or undef
if not found (used when the key is not "expires:id").
Cache::Cache::get_object() returns a Cache::Object instance, which can
tell us the expiry time of the object (and that's the value associted
with the "expires:id" key), or undef if not found.

> If you have chance, maybe you could stop by #catalyst-dev and get a
> commit-bit? Then you can work on this change (and give people a
> chance to test it) in a branch until its ready for trunk..

I'll do so.

BTW, I don't want to hurt anyone, but sometimes I feel that the
Catalyst::Plugin::Session::Store interface is not one of the nicest
and most effective interfaces I've seen.. I feel it's too general, still
too restrictive in practical use, and rather confusing:

* the expiry time is carried independently of the entry it refers to
(ie. two independent calls on the interface API, OTOH the underlying
storage wants both of them in one API call)

* the order in which the corresponding keys (ie. "session:id" and
"expires:id") are set/get is not defined

* so a lot of the implementations use some assumptions (that are not
documented anywhere), just to be able to give optimal solutions (and they
will break if something is changed in the implementation of ::Storage)

* the prefix and key has to be split and mangled in the storage
implementations (a separate namespace and id pair would be more
straightforward, but that's just aesthetics)

I'd like to discuss it a bit, so that I can come up with either POD
patches (so to make those assumptions part of the official API) or maybe
some plan on extending the API (for the long term, with transition path).
Or you just point me to the docs I missed and/or prove me that I
misunderstood something. :-)

norbi

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev
Re: Catalyst::Plugin::Session::Store::File patch to use the Cache::FileCache expiry mechanism [ In reply to ]
On 20 Jan 2009, at 11:21, BUCHMULLER Norbert wrote:
>
> BTW, I don't want to hurt anyone, but sometimes I feel that the
> Catalyst::Plugin::Session::Store interface is not one of the nicest
> and most effective interfaces I've seen.. I feel it's too general,
> still
> too restrictive in practical use, and rather confusing:

<snip>

Yes, it's a bit bollocks - the abstractions bleed into one-another etc.

> I'd like to discuss it a bit, so that I can come up with either POD
> patches (so to make those assumptions part of the official API) or
> maybe
> some plan on extending the API (for the long term, with transition
> path).

nothingmuch and mst have at least a mental map of where things should
go longer term.

If you fancy grabbing them for an explanation and translating that
into POD or TODO notes in the distributions then that'd be great, and
if you have time / fancy doing some of the work towards getting
there, that'd be even better :)

Cheers
t0m


_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev