diff --git a/lib/NGCP/Panel/Controller/Root.pm b/lib/NGCP/Panel/Controller/Root.pm index 45033cb4fa..682af2918a 100644 --- a/lib/NGCP/Panel/Controller/Root.pm +++ b/lib/NGCP/Panel/Controller/Root.pm @@ -27,6 +27,14 @@ __PACKAGE__->config(namespace => ''); sub auto :Private { my($self, $c) = @_; + if ($c->request->path =~/^api\//i) { + $c->log->debug("Root::auto: enable cache"); + NGCP::Panel::Form::dont_use_cache(0); + } else { + $c->log->debug("Root::auto: disable cache"); + NGCP::Panel::Form::dont_use_cache(1); + } + if(defined $c->request->params->{lang} && $c->request->params->{lang} =~ /^\w+$/) { $c->log->debug("checking language"); if($c->request->params->{lang} eq "en") { diff --git a/lib/NGCP/Panel/Form.pm b/lib/NGCP/Panel/Form.pm index 7b9ac49824..ce5c713ac7 100644 --- a/lib/NGCP/Panel/Form.pm +++ b/lib/NGCP/Panel/Form.pm @@ -7,14 +7,25 @@ use Module::Load::Conditional qw/can_load/; use NGCP::Panel::Utils::I18N qw//; my %forms = (); +our $dont_use_cache = 0; + +sub dont_use_cache { + if (scalar @_){ + $dont_use_cache = $_[0]; + } + return $dont_use_cache; +} sub get { my ($name, $c, $create_new) = @_; my $form; - if(exists $forms{$name} - && !($forms{$name}->can('ngcp_no_cache') && $forms{$name}->ngcp_no_cache) + $c->log->debug("Form requested: $name; dont_use_cache: $dont_use_cache; create_new: " + .( $create_new // "undefined" ).";"); + if( !$dont_use_cache && !$create_new + && exists $forms{$name} ) { + $c->log->debug("form is taken from cache"); $form = $forms{$name}; $form->clear(); $form->ctx($c); diff --git a/lib/NGCP/Panel/Form/SubscriberProfile/Profile.pm b/lib/NGCP/Panel/Form/SubscriberProfile/Profile.pm index e388d59590..c81d72d77a 100644 --- a/lib/NGCP/Panel/Form/SubscriberProfile/Profile.pm +++ b/lib/NGCP/Panel/Form/SubscriberProfile/Profile.pm @@ -5,10 +5,6 @@ extends 'HTML::FormHandler'; use HTML::FormHandler::Widget::Block::Bootstrap; -#form has dinamic fields, generated by by field_list, that is not triggered when form is taken from the cache. -#Thus we need to recreate form every time. -has 'ngcp_no_cache' => ( default => '1' ); - has '+widget_wrapper' => ( default => 'Bootstrap' ); has_field 'submitid' => ( type => 'Hidden' ); sub build_render_list {[qw/submitid fields actions/]}