Re: Caching solutions for DBIx::Class

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Caching solutions for DBIx::Class

Justin Hunter
Alex,

yes DBIx::Class::Cursor::Cached is maintained and stable. It should do what you're looking for.

Thanks,
Justin

2011/7/2 Alex Povolotsky <[hidden email]>
Hello!

I'm looking for a fairly trivial (for now) cache solution to prevent multiple reSELECTs.

Internal cache (cache => 1 in search) did not work; DBIx::Class::Cursor::Cached - is it maintainted? Is it stable?

Oleg Pronin mentioned some solution "posted by me", but I could not find it.

Maybe someone can recommend me something?

Alex

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|

Re: Caching solutions for DBIx::Class

Eden Cardim
>>>>> "Alex" == Alex Povolotsky <[hidden email]> writes:

    Alex> Good; how can I set default cache_time for all searches
    Alex> without explicit cache_time?

Have a look at the resultset_attributes method in
DBIx::Class::ResultSource.

--
   Eden Cardim       Need help with your Catalyst or DBIx::Class project?
  Code Monkey                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://blog.edencardim.com/            http://www.shadowcat.co.uk/servers/
http://twitter.com/#!/edenc

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|

Re: Caching solutions for DBIx::Class

Jorge Gonzalez
This is the full configuration for my model, which includes heavy caching (it's a readonly access to a data warehouse which gets updated once a day):

Model::MyDB:
  traits:
    - Caching
    - SchemaProxy
  default_resultset_attributes:
    cache_for: 3600    # cache results for one our
  connect_info:
    dsn: 'dbd:mysql:host=1.2.3.4;database=test'
    user: test
    password: test

The 'Caching' trait is what allows you to use the
DBIx::Class::Cursor::Cached caching. The SchemaProxy trait allows you to specify the default_resultset_attributes once and for all resultsets in this model, without having to specify it in every place you use a RS from this model.

And after that you also have to configure the caching backend:

Plugin::Cache:
  backend:
    class: 'Cache::FastMmap'
    unlink_on_exit: 1
    share_file: /tmp/datafile.cache
    cache_size: 32m

With this configuration I didn't have to touch a single line where queries were being executed. Just added these lines to my Catalyst configuration (after installing the correspoding modules, of course). Modules that I had to install from CPAN:

Catalyst::Plugin::Cache
Cache::FastMmap
Catalyst::TraitFor::Model::DBIC::Schema::Caching
Catalyst::TraitFor::Model::DBIC::Schema::SchemaProxy
DBIx::Class::Cursor::Cached (I think this one is brought by Caching trait as a dependency).

Regards
J.

Jorge González Villalonga
Director Técnico


DAIKON Integración y Desarrollo S.L.
Telf: (+34) 91 188 08 28
Fax: (+34) 91 632 65 42
www.daikon.es

El 03/07/11 19:53, Eden Cardim escribió:
"Alex" == Alex Povolotsky [hidden email] writes:
            
    Alex> Good; how can I set default cache_time for all searches
    Alex> without explicit cache_time?

Have a look at the resultset_attributes method in
DBIx::Class::ResultSource.

  

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|

Re: Caching solutions for DBIx::Class

Fernan Aguero-3-3
Hola Jorge,

first of all many thanks for sharing your tips.

On Mon, Jul 4, 2011 at 10:46 AM, Jorge Gonzalez
<[hidden email]> wrote:

>
> This is the full configuration for my model, which includes heavy caching (it's a readonly access to a data warehouse which gets updated once a day):
>
> Model::MyDB:
>   traits:
>     - Caching
>     - SchemaProxy
>   default_resultset_attributes:
>     cache_for: 3600    # cache results for one our
>   connect_info:
>     dsn: 'dbd:mysql:host=1.2.3.4;database=test'
>     user: test
>     password: test

[snipped]


> With this configuration I didn't have to touch a single line where queries were being executed.

[snipped]

> Regards
> J.

I have one question, though: I have a number of essentially static
tables (very infrequent changes), and some tables that change a lot
during a session (e.g. those that store data from the user's session,
for persistency across logins).

Is there a way to exclude specific tables from the caching?

I've read the docs and I see I can specify the caching (yes/no, TTL)
for every query being executed ...

The problem is that i) I don't want to do this (I prefer your
suggestion to turn on caching for all queriesI; and ii) the queries
for which I'd like to turn off caching are not executed by me, but by
the corresponding plugins (e.g. Session::Store::DBIC;
Session::PerUser).

Anyone has solved this? Suggestions welcome.

--
fernan

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|

Re: Caching solutions for DBIx::Class

Jorge Gonzalez
I can't check it out now, but my best bet would be the following:

a) do as I told in my prior email, so you specify caching strategy for  
most of your tables with almost no effort.

b) for the tables wich you want to have a different caching policy,  
modify the resultset_attributes parameter for that class in the Schema  
class configuration (in the file part which is not rewritten when  
regenerating the schema).

Please try :-)
J.

El 04/07/11, Fernan Aguero <[hidden email]> escribió:

> Hola Jorge,
>
> first of all many thanks for sharing your tips.
>
> On Mon, Jul 4, 2011 at 10:46 AM, Jorge Gonzalez
> <[hidden email]> wrote:
>>
>> This is the full configuration for my model, which includes heavy  
>> caching (it's a readonly access to a data warehouse which gets  
>> updated once a day):
>>
>> Model::MyDB:
>>   traits:
>>     - Caching
>>     - SchemaProxy
>>   default_resultset_attributes:
>>     cache_for: 3600    # cache results for one our
>>   connect_info:
>>     dsn: 'dbd:mysql:host=1.2.3.4;database=test'
>>     user: test
>>     password: test
>
> [snipped]
>
>
>> With this configuration I didn't have to touch a single line where  
>> queries were being executed.
>
> [snipped]
>
>> Regards
>> J.
>
> I have one question, though: I have a number of essentially static
> tables (very infrequent changes), and some tables that change a lot
> during a session (e.g. those that store data from the user's session,
> for persistency across logins).
>
> Is there a way to exclude specific tables from the caching?
>
> I've read the docs and I see I can specify the caching (yes/no, TTL)
> for every query being executed ...
>
> The problem is that i) I don't want to do this (I prefer your
> suggestion to turn on caching for all queriesI; and ii) the queries
> for which I'd like to turn off caching are not executed by me, but by
> the corresponding plugins (e.g. Session::Store::DBIC;
> Session::PerUser).
>
> Anyone has solved this? Suggestions welcome.
>
> --
> fernan
>




_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|

Re: Caching solutions for DBIx::Class

Fernan Aguero-3-3
On Mon, Jul 4, 2011 at 2:25 PM, Jorge Gonzalez <[hidden email]> wrote:

> I can't check it out now, but my best bet would be the following:
>
> a) do as I told in my prior email, so you specify caching strategy for most
> of your tables with almost no effort.
>
> b) for the tables wich you want to have a different caching policy, modify
> the resultset_attributes parameter for that class in the Schema class
> configuration (in the file part which is not rewritten when regenerating the
> schema).
>
> Please try :-)
> J.

Thanks Jorge,

will do, of course. But as you said "I can't check it out now" ... so
it'll have to wait until the weekend :)

I'm anxious to have this working.

--
fernan

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...