{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Adapter for Envoy
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • 日本語コミュニティ
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • Edge/API Management /
avatar image
0
Question by Dave Pickard · Aug 26, 2015 at 02:19 PM · 1.8k Views cachingfilesapigee-access

Caching files in node.js

We're making HTTPS calls from Node.js that require use of a client certificate. The certificate/key & associated password are read in from file and this all works. My concern though is having to read in the files for every request and the question is what is the best way to cache this.

Would using the apigee-access module to access the Edge distributed cache be the appropriate thing to do in these circumstances? Or would it be better to use one of the Node file caches that are available?

Comment
Add comment
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Close

1 Answer

  • Sort: 
avatar image
2
Best Answer

Answer by gnanasekaran · Aug 31, 2015 at 06:21 PM

When i did a similar implementation - i just loaded my cert during initialization, and not in the request handler. So the request handlers need not load the files everytime. But the downside to that is, it is permanently loaded.

Comment
Add comment Show 4 · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dave Pickard · Sep 01, 2015 at 07:41 AM 0
Link

@Mukundha Madhavan - do you know if there is any documentation on where / how initialisation is done? I'm struggling to find any.

avatar image gnanasekaran ♦ Dave Pickard · Sep 01, 2015 at 01:39 PM 1
Link

the script will be run when the proxy is deployed, so behavior is similar to how you run a simple http server in node -

so for eg, you can do something like

cert = fs.readFileSync('mycert.pem')

app.get('/foo',function(req,res){
  //use cert here
})
app.post('/bar',function(req,res){
//use cert here
})
app.listen(8080)

the request handlers are only called based on the incoming request, however the script itself is run during deployment [so cert will be set when you deploy the proxy],

avatar image Dino ♦♦ Dave Pickard   · Sep 02, 2015 at 05:16 PM 0
Link
Dave, just to elaborate on what Mukundha suggested. All the code in the nodejs script will run when the proxy is deployed. The .get and .post handlers get registered at deployment time, though of course that request handling logic only *runs* when the appropriate request comes in. As a small change to what Mukundha showed, you can also do something like this:
var cert = fs.readFileSync('mycert.pem'); // runs at deploy time

// register the .get handler at deploy time
app.get('/foo',function(req,res){ 
  // use cert here; this happens only at the time a GET request arrives
});

// register the .get handler at deploy time
app.post('/bar',function(req,res){
  // use cert here; this happens only when a POST request arrives
});

app.listen(8080); // happens at deploy time
avatar image Dave Pickard Dave Pickard · Sep 03, 2015 at 06:57 AM 0
Link
Thanks guys - helpful replies.

Follow this Question

Answers Answers and Comments

25 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Are cache entries made with apigee-access visible to cache policies? 2 Answers

Invalidate response cache from node.js using apigee-access 2 Answers

Unable to use numeric data in KeyFragment while caching response 2 Answers

lookup cache is not working for subsequent requests 1 Answer

What will happen if cache and KVM have the same key name is used to store a valve at the same time ? 2 Answers

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2021 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Adapter for Envoy
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • 日本語コミュニティ
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Badges