Zend(ZF1) - how to clear cache - caching

I have updated the app.ini file but somewhere someone wrote this code to have used cache. How can I clear the cache?
static $configuration;
if (!$configuration) {
if (Zend_Registry::isRegistered("configuration")) {
$configuration = Zend_Registry::get("configuration");
}
else {
$cache = self::getCache();
if (!$configuration = $cache->load("configuration")) {
$configuration = new Zend_Config_Ini(APPLICATION_PATH . "/config/app.ini", APPLICATION_ENVIRONMENT);
$cache->save($configuration, "configuration");
}
Zend_Registry::set("configuration", $configuration);
}
}

Related

Respond with Cache headers for images in Ktor

What is the correct way to send back cache headers for static images being served by Ktor?
I have the following Ktor setup:
In my main:
embeddedServer(
Netty,
watchPaths = listOf("module"),
module = Application::module,
port = if (ENV.env == LOCAL) {
8080
} else {
80
}
).apply {
start(wait = true)
}
and then outside the main:
fun Application.module() {
if (ENV.env != LOCAL) {
install(ForwardedHeaderSupport)
install(XForwardedHeaderSupport)
install(HttpsRedirect)
}
install(CachingHeaders) {
options { outgoingContent ->
when (outgoingContent.contentType?.withoutParameters()) {
ContentType.Image.Any -> CachingOptions(CacheControl.MaxAge(maxAgeSeconds = 30 * 24 * 60 * 60))
else -> null
}
}
}
install(Compression) {
gzip {
priority = 1.0
}
deflate {
priority = 10.0
minimumSize(1024) // condition
}
}
routing {
static("/js/") {
resources("/js/")
}
static("/css/") {
resources("/css/")
}
static("/favicons") {
resources("/favicons/")
}
static("/img/") {
resources("/static/img/")
resources("/static/images/")
resources("/background/")
resources("/logos/")
resources("/icons/")
}
}
}
The images however are coming back with no caching headers, any ideas?
Update:
Changing ContentType.Image.Any to ContentType.Image.JPEG seems to work. Looking at the source code of Image, it seems to map to ContentType(image, *) but is not matching any image type at all.
install(CachingHeaders) {
options { outgoingContent ->
when (outgoingContent.contentType?.withoutParameters()) {
ContentType.Image.JPEG -> CachingOptions(
cacheControl = CacheControl.MaxAge(
mustRevalidate = false,
maxAgeSeconds = 30 * 24 * 60 * 60,
visibility = CacheControl.Visibility.Public
)
)
else -> null
}
}
}
Filed a bug in the meantime:
https://github.com/ktorio/ktor/issues/1366
Turns out that a standard eqauls check is being done on * instead of the actual file type, so using match instead sorts that problem out:
install(CachingHeaders) {
options { outgoingContent ->
if (outgoingContent.contentType?.withoutParameters()?.match(ContentType.Image.Any) == true) {
CachingOptions(
cacheControl = CacheControl.MaxAge(
mustRevalidate = false,
maxAgeSeconds = 6 * 30 * 24 * 60 * 60,
visibility = CacheControl.Visibility.Public
)
)
} else {
null
}
}
}
You can set caching headers by content type using: https://ktor.io/servers/features/caching-headers.html

Laravel 5.3 database transaction issue?

I have used more time with Laravel 5.0 on database transaction but when I change to Laravel 5.3.* it not work as I want even I have disabled commit() method all data still continue insert into database.
if ($request->isMethod('post')) {
DB::beginTransaction();
$cats = new Cat();
$cats->parent_id = $this->request->input('category_id');
$cats->status = ($this->request->input('status')) ? $this->request->input('status') : 0;
if ($res['cat'] = $cats->save()) {
$catD = new CategoryDescriptions();
$catD->category_id = $cats->id;
$catD->language_id = 1;
$catD->name = $this->request->input('en_name');
if ($res['cat2'] = $catD->save()) {
$catD2 = new CategoryDescriptions();
$catD2->category_id = $cats->id;
$catD2->language_id = 2;
$catD2->name = $this->request->input('kh_name');
$res['all'] = $catD2->save();
}
}
if ($res) {
//DB::commit();
return $res;
}
return [false];
}
Check this line ($res['cat'] is a boolean):
if($res['cat'] = $cats->save()) {
And this ($res is an array. You compare an array as boolean!):
if($res){
The right condition should be:
$res = array(); // the first line of your method
// .... your http method check, start transaction, etc.
if (!in_array(false, $res, true)) { // check if array doesn't contain 'false values'
DB::commit();
}

Modify the MY_Router.php file for QUERY STRING Codeigniter 3.0.6

I use codeigniter 3.0.6 query string like
index.php?d=directoryt&c=controller
index.php?d=directory&c=controller&m=function
How ever having two get methods for directory and controller is a bit long.
Question Is there any way to modify the protected function
_set_routing() function using a MY_Router.php to get it so it will pick up the directory and controller by using one query only like example below.
index.php?route=directory/controller
// If need to get function
index.php?route=directory/controller&m=function
What have tried so far
<?php
class MY_Router extends CI_Router {
protected function _set_routing()
{
// Load the routes.php file. It would be great if we could
// skip this for enable_query_strings = TRUE, but then
// default_controller would be empty ...
if (file_exists(APPPATH.'config/routes.php'))
{
include(APPPATH.'config/routes.php');
}
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/routes.php'))
{
include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
}
// Validate & get reserved routes
if (isset($route) && is_array($route))
{
isset($route['default_controller']) && $this->default_controller = $route['default_controller'];
isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes'];
unset($route['default_controller'], $route['translate_uri_dashes']);
$this->routes = $route;
}
// Are query strings enabled in the config file? Normally CI doesn't utilize query strings
// since URI segments are more search-engine friendly, but they can optionally be used.
// If this feature is enabled, we will gather the directory/class/method a little differently
if ($this->enable_query_strings)
{
// If the directory is set at this time, it means an override exists, so skip the checks
if ( ! isset($this->directory))
{
$_route = isset($_GET['route']) ? trim($_GET['route'], " \t\n\r\0\x0B/") : '';
if ($_route !== '')
{
echo $_route;
$this->uri->filter_uri($_route);
$this->set_directory($_route);
}
}
// Routing rules don't apply to query strings and we don't need to detect
// directories, so we're done here
return;
}
// Is there anything to parse?
if ($this->uri->uri_string !== '')
{
$this->_parse_routes();
}
else
{
$this->_set_default_controller();
}
}
}
config.php
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = TRUE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';
// Modifyed in MY_Router.php
$config['route'] = 'route';
I have it working
<?php
class MY_Router extends CI_Router {
protected function _set_routing() {
if (file_exists(APPPATH.'config/routes.php'))
{
include(APPPATH.'config/routes.php');
}
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/routes.php'))
{
include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
}
// Validate & get reserved routes
if (isset($route) && is_array($route))
{
isset($route['default_controller']) && $this->default_controller = $route['default_controller'];
isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes'];
unset($route['default_controller'], $route['translate_uri_dashes']);
$this->routes = $route;
}
if ($this->enable_query_strings) {
if ( ! isset($this->directory))
{
$route = isset($_GET['route']) ? trim($_GET['route'], " \t\n\r\0\x0B/") : '';
if ($route !== '')
{
$part = explode('/', $route);
$this->uri->filter_uri($part[0]);
$this->set_directory($part[0]);
if ( ! empty($part[1])) {
$this->uri->filter_uri($part[1]);
$this->set_class($part[1]);
// Testing function atm
if ( ! empty($_GET['function']))
{
$this->uri->filter_uri($_GET['function']);
$this->set_method($_GET['function']);
}
$this->uri->rsegments = array(
1 => $this->class,
2 => $this->method
);
}
} else {
$this->_set_default_controller();
}
}
// Routing rules don't apply to query strings and we don't need to detect
// directories, so we're done here
return;
}
// Is there anything to parse?
if ($this->uri->uri_string !== '')
{
$this->_parse_routes();
}
else
{
$this->_set_default_controller();
}
}
}

How to comple Sass with scssphp compiler cache

Less PHP (http://leafo.net/lessphp/docs/) has a great method
function autoCompileLess($inputFile, $outputFile) {
// load the cache
$cacheFile = $inputFile.".cache";
if (file_exists($cacheFile)) {
$cache = unserialize(file_get_contents($cacheFile));
} else {
$cache = $inputFile;
}
$less = new lessc;
$newCache = $less->cachedCompile($cache);
if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) {
file_put_contents($cacheFile, serialize($newCache));
file_put_contents($outputFile, $newCache['compiled']);
}
}
autoCompileLess('myfile.less', 'myfile.css');
Is there any option to do same thing with http://leafo.net/scssphp/, for SASS? I can't find alternative to cachedCompile() with scssphp.

smarty path problem

here is my folder
index.php
smartyhere
-Smarty.class.php
admin
-index.php
-users.php
in index.php -> $smarty->display('index.tpl');
in admin/index.php -> $smarty->display('adminindex.tpl');
got error Smarty error: unable to read resource: "adminindex.tpl"
any idea ?
thx
try to understand code
which urlencode is doing path
<?php
print_r($file);
if (isset($file)) {
$var = explode("-", $file);
print_r($var);
$prefix = $var[0];
$script = $var[1];
} else {
$file = "c-home1";
$prefix = "c";
$script = "home";
$modid = 0;
}
if ($script=="") {
$script="prod_list";
}
/*
* following code finds out the modules from suffix
* and find out the script name
*/
switch ($prefix) {
case "c":
$module = "content";
break;
case "m":
$module = "myaccount";
break;
default:
$module = "content";
break;
}
$smarty->assign("module",$module);
/*
* following code finds out the modules from suffix and
* find out the script name
*/
$include_script .= $module."/".$script.".php";
if (file_exists($include_script)) {
include_once $include_script;
} else {
include_once "content/error.php";
}
if ($script!='home') {
if ($script == 'termsandcondition') {
$smarty->display("content/termsandcondition.tpl");
} else {
$smarty->display("template.tpl");
}
} else {
$smarty->display("template_home.tpl");
$smarty->assign("msg", $msg);
$smarty->assign("msglogin", $msglogin);
}

Resources