은 내가 입력 할 때조차도 어리석은 질문처럼 보이지만 사전에 감사드립니다. 그러나 어쨌든 여기에 있습니다.Perl 촉매 DBIx 커서 캐시 - 삭제 방법?
나는 DBIx를 사용하여 기본 촉매 응용 프로그램 : 클래스에 '저자'와 관련된 '책'테이블이있다. 또한 DBIx :: Class :: Cursor :: Cached을 적절하게 사용하여 데이터를 캐시합니다.
문제는 편집 후에 실제로 만료되기 전에 캐시 된 데이터를 삭제해야한다는 것입니다.
) 저자 -> show_author_and_books 결과 집합을 가져오고 캐시합니다.
2)를 Book-> edit_do Author-> show_author_and_books 요청에서 캐시 된 데이터를 삭제해야.
아래의 기본/적절한 설정을 참조하십시오.
- MyApp.pm 정의에는 백엔드 'Cache :: FileCache'캐시가 포함됩니다.
__PACKAGE__->config(
name => 'MyApp',
...
'Plugin::Cache' => { 'backend' => { class => 'Cache::FileCache',
cache_root => "./cache",
namespace => "dbix",
default_expires_in => '8 hours',
auto_remove_stale => 1
}
},
...
- '캐시'특성은 'DBIx이 :: 클래스 :: 커서 :: 캐시'를 사용하여 세트의 MyApp :: 모델 :: DB 정의.
...
__PACKAGE__->config(
schema_class => 'MyApp::Schema',
traits => [ 'Caching' ],
connect_info => { dsn => '<dsn>',
user => '<user>',
password => '<password>',
cursor_class => 'DBIx::Class::Cursor::Cached'
}
);
...
- 결과 집합 캐시 - 'show_author_and_books'방법에의 MyApp :: 컨트롤러 :: Author.pm 정의.
...
sub show_author_and_books :Chained('base') :PathPart('') :Args(0)
{
my ($self, $c) = @_;
my $author_id = $c->request->params->{author_id};
my $author_and_books_rs = $c->stash->{'DB::Author'}->search({ author_id => $author_id },
{ prefetch => 'book' },
cache_for => 600 }); # Cache results for 10 minutes.
# More interesting stuff, but no point calling $author_and_books_rs->clear_cache here, it would make no sense:s
...
}
...
- 번호부 항목을 업데이트하고 그래서 show_author_and_books에 캐시 된 데이터를 무효화 'edit_do'방법의 MyApp :: 컨트롤러 :: Book.pm 정의.
...
sub edit_do :Chained('base') :PathPart('') :Args(0)
{
my ($self, $c) = @_;
# Assume stash contains a book for some author, and that we want to update the description.
my $book = $c->stash->{'book'}->update({ desc => $c->request->params->{desc} });
# How do I now clear the cached DB::Author data to ensure the new desc is displayed on next request to 'Author->show_author_and_books'?
# HOW DO I CLEAR CACHED DB::Author DATA?
...
}
은 당연히 나는 Author-> show_author_and_books에 정의 된 $ author_and_books_rs가, 방법 'clear_cache'를 포함 알고 있어요,하지만 분명히이 Book-> edit_do의 범위를 벗어 (다른 문제는있을 수 있음).
그래서 다시 DBIx 요청을 할 수있는 올바른 방법은 ... 에 따라, show_author_and_books 한 후 전화를 다시 'clear_cache'그게 아니면 그냥이 $ 같은 것을 말할 수있는보다 직접적인 방법이있다 c-> cache -> ('DB :: Author') -> clear_cache?
다시 한 번 감사드립니다.
추신.나는이 내일 볼 때 확실 해요, 질문의 전체 어리 석음이 나를 때리는 것 :의
제안 해 주셔서 감사합니다.하지만 아아는 D :: C :: Cursor의 모든 데이터로 작동하지 않습니다. :: 단일 네임 스페이스 (예 : 캐시에 'DB :: Author'데이터, 'DB :: Books', 'DB :: Other'가 포함되어 있음)에 캐시되어 있으므로 모든 것이 명확 해집니다. 특정 세트 나 특정 네임 스페이스를 만료시킬 수 있어야하므로 대신 다음 해결책을 찾아야합니다. – user647248