Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public cache functions #212

Closed
peter-mw opened this issue Jun 13, 2014 · 9 comments
Closed

Public cache functions #212

peter-mw opened this issue Jun 13, 2014 · 9 comments

Comments

@peter-mw
Copy link
Contributor

Hello,

I was able to successfully integrate your library in my project.
Thank you for the great work. Idiorm in ingenious!
I can now make super complex queries with no problem.

I have a situation here when i need to use my own cache functions

Since those methods are protected:
https://github.com/j4mie/idiorm/blob/master/idiorm.php#L1538
https://github.com/j4mie/idiorm/blob/master/idiorm.php#L1548
https://github.com/j4mie/idiorm/blob/master/idiorm.php#L1565

I cannot override them
Can you please make them public or suggest some way i can swap them with my own functions

Thanks

@treffynnon
Copy link
Collaborator

What do you need to do this for? Why do you need to overload those methods?
Give me a little more information so I can try to recommend a way of doing
it.

@peter-mw
Copy link
Contributor Author

I have put Idiorm adapter in my CMS yesterday
https://github.com/microweber/microweber/blob/new/src/Microweber/Adapters/Orm/IdiOrm.php

Now i want to migrate all my queries to Idiorm and ditch the old ugly DB functions.

The problem is that i have internal cache system i want to use. The CMS is query heavy and relies on cache (Files, APC or memcache)

I need a way to swap the idiorm cache functions.

I need to cache the data on _execute and clear the cache on save

Maybe adding a configure option will be the best way to use custom functions

@peter-mw
Copy link
Contributor Author

Do you want me to try to implement this?
I will try the following idea - to pass
ORM::configure('cache_hash_callback', function($my_class){ });
ORM::configure('cache_save_callback', function($my_class){ });
ORM::configure('cache_delete_callback', function($my_class){ });

and somehow work this out in Idirom class

I badly need external caching mechanism

@treffynnon
Copy link
Collaborator

So in this case why don't you just cache the result in your adapter rather than in Idiorm directly?

@peter-mw
Copy link
Contributor Author

Hi, this is test adapter and just made it to see if i can hack the table prefix

I don't want to override the functions by extending them and breaking the compatibility with the ORM class. If i use my adapter approach i will be able to cache the result, but have no ability to clean the cache, because i don't know when the save function is executed

On the other hand:
I want to integrate Paris too, in this case i would like to use caching there though idiom
Paris fits very nice and though it i will be able to overcome my table prefix problem, but still have the caching problem.

If we can put a cache callback functions though ORM::configure this will be the cleanest approach and also work on multiple connections

@treffynnon
Copy link
Collaborator

I am really not so sure about this as caching is not really a core concern of Idiorm itself. On the other hand it does seem logical that as we do have caching that it should be more controllable.

If you do decide to implement this then to ensure it gets included please remember to include documentation and tests in your pull request. Please remember to update the changelog in the readme too.

@peter-mw
Copy link
Contributor Author

Hi,
I will try to integrate this in the next days. Will update this issue

@peter-mw
Copy link
Contributor Author

I have added support of callbacks

Now you can set custom functions via

ORM::configure('cache_query_result', function ($hash) {

});
ORM::configure('check_query_cache', function ($cache_key,$connection_name) {

});
ORM::configure('clear_cache', function ($connection_name) {

});

@treffynnon
Copy link
Collaborator

Closing and moving discussion to pull request.

treffynnon pushed a commit that referenced this issue Jun 22, 2014
This is a combination of 20 commits:
added cache callback #212

added test

Added text for custom cache

formating and tests

added caching_auto_clear option

moved custom cache test for php 5.3+

fixed ConfigTest.php

tabs to spaces

formating

formating

added `create_cache_key` callback option

added $table_name to clear cache function

added $table_name to _create_cache_key

added missing params

added $table_name to cache_query_result

formating

tabs

added $table_name to check_query_cache

unify cache parameters order

`table_name` is more important than `connection_name`

formating
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants